from machine import Pin
from time import sleep

# Segment pins
a = Pin(0, Pin.OUT)
b = Pin(1, Pin.OUT)
c = Pin(2, Pin.OUT)
d = Pin(3, Pin.OUT)
e = Pin(4, Pin.OUT)
f = Pin(5, Pin.OUT)
g = Pin(6, Pin.OUT)

# Button pin
button = Pin(10, Pin.IN, Pin.PULL_DOWN)

# Digit patterns (0–9) for common cathode
digit_patterns = [
    [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 digit
def display_digit(num):
    pattern = digit_patterns[num]
    a.value(pattern[0])
    b.value(pattern[1])
    c.value(pattern[2])
    d.value(pattern[3])
    e.value(pattern[4])
    f.value(pattern[5])
    g.value(pattern[6])

# Initial state
current = 0
display_digit(current)

while True:
    state = button.value()
    if  state == 1:  # button just pressed
        current = (current + 1) % 10
        display_digit(current)
        sleep(0.2)  # debounce delay
BOOTSELLED1239USBRaspberryPiPico©2020RP2-8020/21P64M15.00TTT