import utime
#GPIO pins for 7-segment display segments (a-g)
segments = [
machine.Pin(0, machine.Pin.OUT),
machine.Pin(1, machine.Pin.OUT),
machine.Pin(2, machine.Pin.OUT),
machine.Pin(3, machine.Pin.OUT),
machine.Pin(4, machine.Pin.OUT),
machine.Pin(5, machine.Pin.OUT),
machine.Pin(6, machine.Pin.OUT),
]
dp = machine.Pin(7, machine.Pin.OUT)
digit = [
machine.Pin(8, machine.Pin.OUT),
machine.Pin(9, machine.Pin.OUT),
machine.Pin(10, machine.Pin.OUT),
machine.Pin(11, machine.Pin.OUT),
]
# pin states for each digit to display numbers 0-9
number_map = [
[1, 1, 1, 1, 1, 1, 0], # 0
[0, 1, 1, 0, 0, 0, 0], # 1
[1, 1, 0, 1, 1, 0, 1], # 2
[1, 1, 1, 1, 0, 0, 1], # 3
[0, 1, 1, 0, 0, 1, 1], # 4
[1, 0, 1, 1, 0, 1, 1], # 5
[1, 0, 1, 1, 1, 1, 1], # 6
[1, 1, 1, 0, 0, 0, 0], # 7
[1, 1, 1, 1, 1, 1, 1], # 8
[1, 1, 1, 1, 0, 1, 1] # 9
]
digit_map = [
[1, 0, 0, 0], # digit 1
[0, 1, 0, 0], # digit 2
[0, 0, 1, 0], # digit 3
[0, 0, 0, 1], # digit 4
]
#function to display a specific number on the 7-segment display
def display_number(number):
segments_values = number_map[number]
# print(digit_values)
for i in range(len(segments)):
segments[i].value(not segments_values[i])
while True:
for number in range(10):
for j in range(len(digit)):
digit_values = digit_map[j]
for k in range(len(digit)):
display_number(number)
digit[k].value(digit_values[k])
dp.value(0)
utime.sleep_ms(500) # Delay between numbers