from machine import Pin, Timer
from time import sleep
led_18 = Pin(18, Pin.OUT)
led_5 = Pin(5, Pin.OUT)
button = Pin(19, Pin.IN, Pin.PULL_UP)
switch = 0
def handler_0(tim0):
global switch
if switch == 0:
tim0.deinit()
switch = 0
elif switch == 1:
led_18.value(not led_18.value())
elif switch == 2:
led_5.value(not led_5.value())
else:
switch =0
tim0.deinit()
tim0 = Timer(0)
while True:
if button.value()==0:
sleep(0.1)
if button.value () == 0:
switch = switch +1
elif switch == 1 :
led_5.value(0)
tim0.init(period = 1000, mode = Timer.PERIODIC, callback = handler_0)
elif switch == 2:
led_18.value(0)
tim0.init(period = 1500, mode = Timer.PERIODIC, callback = handler_0)
else :
switch = 0
tim0.deinit()
push_button = "The value of the switch {}"
print(push_button.format(switch), end="\r")