# display 00 to 99 by using push button in increment and decrement both way
from machine import Pin
from time import sleep
# Define pins for the first seven-segment display
pins1 = [Pin(32, Pin.OUT), Pin(33, Pin.OUT), Pin(25, Pin.OUT), Pin(26, Pin.OUT),
Pin(27, Pin.OUT), Pin(12, Pin.OUT), Pin(14, Pin.OUT)]
# Define pins for the second seven-segment display
pins2 = [Pin(23, Pin.OUT), Pin(22, Pin.OUT), Pin(19, Pin.OUT), Pin(18, Pin.OUT),
Pin(5, Pin.OUT), Pin(4, Pin.OUT), Pin(2, Pin.OUT)]
# Define the character patterns for numbers 0-9
char = [[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
[1, 0, 0, 1, 1, 0, 0], # 4
[0, 1, 0, 0, 1, 0, 0], # 5
[0, 1, 0, 0, 0, 0, 0], # 6
[0, 0, 0, 1, 1, 1, 1], # 7
[0, 0, 0, 0, 0, 0, 0], # 8
[0, 0, 0, 0, 1, 0, 0]] # 9
# Initialize button pins for counting up and down
button_up = Pin(0, Pin.IN, Pin.PULL_UP)
button_down = Pin(16, Pin.IN, Pin.PULL_UP)
# Function to display a number on the two seven-segment displays
def display_number(number):
for i in range(7):
pins1[i].value(char[number // 10][i]) # Display tens digit on first display
pins2[i].value(char[number % 10][i]) # Display units digit on second display
# Initialize number
number = 0
# Main loop
while True:
# Check if the count up button is pressed
if not button_up.value():
number = (number + 1) % 100 # Increment number, ensure it wraps around 0-99
display_number(number)
sleep(0.2) # Debounce delay
# Check if the count down button is pressed
if not button_down.value():
number = (number - 1) % 100 # Decrement number, ensure it wraps around 0-99
display_number(number)
sleep(0.2) # Debounce delay