from machine import Pin
import time
# Define GPIO pins for segments A-G respectively
segments = [5, 18, 19, 21, 22, 23, 25] # Update these pins based on your wiring
# GPIO pin setup
pins = [Pin(pin, Pin.OUT) for pin in segments]
# Define the digit patterns: 0-9. Each digit is represented by a 7-element list
# corresponding to segments A-G. 0 for off, 1 for on.
digits = [
[0, 0, 0, 0, 0, 0, 1], # 0
[1, 0, 0, 1, 1, 1, 1], # 1
[0, 0, 1, 0, 0, 1, 0], # 2
[0, 0, 0, 0, 1, 1, 0], # 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
]
def display_number(number):
for i, pin in enumerate(pins):
pin.value(digits[number][i])
# Main loop
while True:
for number in range(10):
display_number(number)
time.sleep(1) # Display each number for 1 second