import machine
import utime
# GPIO pins for 7-segment display segments (a-g) for display 1
segments_1 = [
machine.Pin(0, machine.Pin.OUT), # a
machine.Pin(1, machine.Pin.OUT), # b
machine.Pin(2, machine.Pin.OUT), # c
machine.Pin(3, machine.Pin.OUT), # d
machine.Pin(4, machine.Pin.OUT), # e
machine.Pin(5, machine.Pin.OUT), # f
machine.Pin(6, machine.Pin.OUT) # g
]
# GPIO pins for 7-segment display segments (a-g) for display 2
segments_2 = [
machine.Pin(7, machine.Pin.OUT), # a
machine.Pin(8, machine.Pin.OUT), # b
machine.Pin(9, machine.Pin.OUT), # c
machine.Pin(10, machine.Pin.OUT), # d
machine.Pin(11, machine.Pin.OUT), # e
machine.Pin(12, machine.Pin.OUT), # f
machine.Pin(13, machine.Pin.OUT) # g
]
# 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
]
# function to display a specific number on a specific 7-segment display
def display_number(segments, number):
segments_values = number_map[number]
for i in range(len(segments)):
segments[i].value(segments_values[i])
while True:
for number in range(100):
tens = number // 10 # Tens digit
ones = number % 10 # Ones digit
display_number(segments_1, tens) # Display tens on the first 7-segment
display_number(segments_2, ones) # Display ones on the second 7-segment
utime.sleep_ms(1000) # Delay between numbers (1 second)