from machine import Pin
import time
Pin1 = 26
Pin2 = 0
Pin3 = 1
Button = 27
ButtonCounter = 0
lastDebounceTime = 0
debounceDelay = 50
def setup():
global Pin1, Pin2, Pin3, Button
Pin(Pin1, Pin.OUT)
Pin(Pin2, Pin.OUT)
Pin(Pin3, Pin.OUT)
Pin(Button, Pin.IN, Pin.PULL_DOWN)
def loop():
global ButtonCounter, lastDebounceTime
buttonState = Pin(Button).value()
if buttonState == 1 and (time.ticks_ms() - lastDebounceTime) > debounceDelay:
ButtonCounter += 1
lastDebounceTime = time.ticks_ms()
if ButtonCounter == 1:
Pin(Pin1, Pin.OUT).value(1)
time.sleep(1)
Pin(Pin1, Pin.OUT).value(0)
elif ButtonCounter == 2:
Pin(Pin2, Pin.OUT).value(1)
time.sleep(1)
Pin(Pin2, Pin.OUT).value(0)
elif ButtonCounter == 3:
Pin(Pin3, Pin.OUT).value(1)
time.sleep(1)
Pin(Pin3, Pin.OUT).value(0)
elif ButtonCounter == 4:
Pin(Pin1, Pin.OUT).value(1)
Pin(Pin2, Pin.OUT).value(1)
Pin(Pin3, Pin.OUT).value(1)
time.sleep(1)
Pin(Pin1, Pin.OUT).value(0)
Pin(Pin2, Pin.OUT).value(0)
Pin(Pin3, Pin.OUT).value(0)
ButtonCounter = 0