import time
from machine import Pin
from machine import ADC, Pin
time.sleep(0.1) # Wait for USB to become ready
print("Hello, Pi Pico!")
button = Pin(20,mode = Pin.IN, pull = Pin.PULL_UP)
led1 = Pin(17, Pin.OUT)
led2 = Pin(18, Pin.OUT)
led3 = Pin(19, Pin.OUT)
isPressed = False
val = 0
def addValue(val):
val += 1
if val > 7:
val = 0
return val
def switchLED(led1,led2,led3,val):
if (val & 0b001):
led1.on()
else:
led1.off()
if (val & 0b010):
led2.on()
else:
led2.off()
if (val & 0b100):
led3.on()
else:
led3.off()
return
while True:
if button.value() == 0 and not isPressed:
print("button pressed")
val = addValue(val)
switchLED(led1,led2,led3,val)
print(val)
isPressed = True
time.sleep(0.050)
if button.value() == 1 and isPressed:
isPressed = False
time.sleep(0.050)