from machine import Pin
import time
segments = [Pin(12, Pin.OUT), Pin(14, Pin.OUT), Pin(27, Pin.OUT), Pin(26, Pin.OUT), Pin(25, Pin.OUT), Pin(33, Pin.OUT), Pin(32, Pin.OUT)]
digits = [
[0, 0, 0, 0, 0, 0, 1],
[1, 0, 0, 1, 1, 1, 1],
[0, 0, 1, 0, 0, 1, 0],
[0, 0, 0, 0, 1, 1, 0],
[1, 0, 0, 1, 1, 0, 0],
[0, 1, 0, 0, 1, 0, 0],
[0, 1, 0, 0, 0, 0, 0],
[0, 0, 0, 1, 1, 1, 1],
[0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 1, 0, 0]
]
switch_up = Pin(5, Pin.IN, Pin.PULL_UP)
switch_down = Pin(4, Pin.IN, Pin.PULL_UP)
def display_digit(digit):
for i in range(7):
segments[i].value(digits[digit][i])
def increment_counter():
global counter
counter = (counter + 1) % 10
def decrement_counter():
global counter
counter = (counter - 1) % 10
counter = 0
while True:
if not switch_up.value():
increment_counter()
time.sleep(0.2)
if not switch_down.value():
decrement_counter()
time.sleep(0.2)
display_digit(counter)
time.sleep(0.01)