from machine import Pin
import utime
# Define the segments for the 7-segment display
segments = [Pin(i, Pin.OUT) for i in range(7)]
# Define the digit patterns for 0-9
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, 0, 0, 1, 1] # 9
]
# Function to display a digit on the 7-segment display
def display_digit(digit):
pattern = digit_patterns[digit]
for segment, value in zip(segments, pattern):
segment.value(value)
# Define the buttons
button_increment = Pin(14, Pin.IN, Pin.PULL_DOWN)
button_reset = Pin(15, Pin.IN, Pin.PULL_DOWN)
# Initialize click count
click_count = 0
# Debounce delay
debounce_delay = 200
while True:
# Check if the increment button is pressed
if button_increment.value() == 1:
click_count += 1
if click_count > 9:
click_count = 0
display_digit(click_count)
utime.sleep_ms(debounce_delay) # Debounce delay
# Check if the reset button is pressed
if button_reset.value() == 1:
click_count = 0
display_digit(click_count)
utime.sleep_ms(debounce_delay) # Debounce delay
utime.sleep_ms(10) # Short delay to avoid busy-waiting
pico:GP0
pico:GP1
pico:GND.1
pico:GP2
pico:GP3
pico:GP4
pico:GP5
pico:GND.2
pico:GP6
pico:GP7
pico:GP8
pico:GP9
pico:GND.3
pico:GP10
pico:GP11
pico:GP12
pico:GP13
pico:GND.4
pico:GP14
pico:GP15
pico:GP16
pico:GP17
pico:GND.5
pico:GP18
pico:GP19
pico:GP20
pico:GP21
pico:GND.6
pico:GP22
pico:RUN
pico:GP26
pico:GP27
pico:GND.7
pico:GP28
pico:ADC_VREF
pico:3V3
pico:3V3_EN
pico:GND.8
pico:VSYS
pico:VBUS
sevseg1:COM.1
sevseg1:COM.2
sevseg1:A
sevseg1:B
sevseg1:C
sevseg1:D
sevseg1:E
sevseg1:F
sevseg1:G
sevseg1:DP
btn1:1.l
btn1:2.l
btn1:1.r
btn1:2.r
btn2:1.l
btn2:2.l
btn2:1.r
btn2:2.r