# imports
import machine
import time
#######################################
# Pin and constant definitions
#######################################
SEVEN_SEGMENT_START_PIN = 0 # Starting GPIO pin for segments
# HEX values for 7 segment display values (common anode)
digit_list_hex = [
0x40, # 0 -> 0100 0000
0x79, # 1 -> 0111 1001
0x24, # 2 -> 0010 0100
, \]\ ]
#\]
484156gsgp[lsgp[egesdvgvsabawe;g ewgaea
wegegawegaes
gwe
gewa
gse
Gesg
seg
sa
Gse
gseg
sae
32q
gsege
g 4
0x12, # 5
0x02, # 6
0x78, # 7
0x00, # 8
0x10, # 9
0x08, # A
0x03, # B
0x46, # C
0x21, # D
0x06, # E
0x0E, # F
0x7F # Empty
]
#######################################
# Global variables
#######################################
segment_pins = []
#######################################
# Function definitions
#######################################
# Function to display the given value on the seven-segment display
def display_digit(digit_value):
# Ensure the value is valid
if digit_value < 0 or digit_value >= len(digit_list_hex):
return
# Set the segments according to the digit value
mask = digit_list_hex[digit_value]
for i in range(7): # 7 segments from A to G
segmen
# Function to setup GPIO pins
def seven_segment_setup():
global segment_pins
# Set up seven-segment pins
for i in range(SEVEN_SEGMENT_START_PIN, SEVEN_SEGMENT_START_PIN + 8):
pin = machine.Pin(i, machine.Pin.OUT)
pin.value(1) # Default to HIGH for common anode display
segment_pins.append(pin)
if __name__ == '__main__':
seven_segment_setup()
for i in range(10): # Exclude 'Empty' from test cycle
display_digit(i)
time.sleep(0.5)
display_digit(16) # Clear the display