from machine import Timer, Pin, PWM
pwm = PWM(Pin(21), freq=50)
push = Pin(14, Pin.IN, Pin.PULL_UP)
def timer (x):
global servo, direccion
pwm.duty(int(servo))
if direccion:
servo = servo + 1
if servo > 125:
direccion = 0
else:
servo = servo - 1
if servo < 25:
direccion = 1
def mover (y):
global direccion
direccion = not direccion
t0 = Timer(0)
t0.init(period=10, mode=Timer.PERIODIC, callback=timer)
push.irq(trigger=Pin.IRQ_FALLING, handler=mover)
servo = 25
direccion = 1
while(1):
pass