from machine import Pin, ADC,PWM,Timer
from time import sleep
led = Pin(22,Pin.OUT)
button_pin19 = Pin(19, Pin.IN, Pin.PULL_DOWN)
pwm0 = PWM(Pin(21))
pwm0.freq(50)
inc = 25
tim1 = Timer(1)
tim2 = Timer(2)
pwm0.duty(25)
def handler_0(tim0):
global inc
if inc <= 125:
pwm0.duty(inc)
inc=inc+5
print(inc)
else:
tim0.deinit()
tim1.init(period=100, mode=Timer.PERIODIC, callback=handler_1)
tim0 = Timer(0)
tim0.init(period=500, mode=Timer.PERIODIC, callback=handler_0)
def handler_1(tim1):
global inc
if inc >5:
pwm0.duty(inc)
inc=inc-5
print(inc)
else:
inc=25
tim1.deinit()
tim0.init(period=100, mode=Timer.PERIODIC, callback=handler_0)
def handler_2(tim2):
led.value(not led.value())
temp=1
while True:
if button_pin19.value() == 1 and temp == 1:
tim2.init(period=500, mode=Timer.PERIODIC, callback=handler_2)
temp = 0
elif button_pin19.value() == 1 and temp == 0:
tim2.deinit()
led.value(0)
temp=1