import machine
import time
# Updated GPIO pins for 7-segment segments a-g
segments = {
'a': machine.Pin(2, machine.Pin.OUT),
'b': machine.Pin(3, machine.Pin.OUT),
'c': machine.Pin(4, machine.Pin.OUT),
'd': machine.Pin(5, machine.Pin.OUT),
'e': machine.Pin(6, machine.Pin.OUT),
'f': machine.Pin(7, machine.Pin.OUT),
'g': machine.Pin(8, machine.Pin.OUT),
}
# 7-segment pattern for digits 0-9
digits = {
0: ['a', 'b', 'c', 'd', 'e', 'f'],
1: ['b', 'c'],
2: ['a', 'b', 'g', 'e', 'd'],
3: ['a', 'b', 'c', 'd', 'g'],
4: ['f', 'g', 'b', 'c'],
5: ['a', 'f', 'g', 'c', 'd'],
6: ['a', 'c', 'd', 'e', 'f', 'g'],
7: ['a', 'b', 'c'],
8: ['a', 'b', 'c', 'd', 'e', 'f', 'g'],
9: ['a', 'b', 'c', 'd', 'f', 'g'],
}
# Function to display a digit (common cathode)
def display_number(n):
# Turn off all segments
for seg in segments.values():
seg.value(0)
# Turn on the required segments
for seg_name in digits[n]:
segments[seg_name].value(1)
# Main loop: count down from 9 to 0
while True:
for i in range(9, -1, -1): # Count from 9 to 0
display_number(i)
time.sleep(1)