from machine import Timer, PWM, Pin
pwm = PWM(Pin(23), freq=50)
push_1 = Pin(12,Pin.IN,Pin.PULL_UP)
push_2 = Pin(14,Pin.IN,Pin.PULL_UP)
def boton_1 (x):
global direccion
direccion = not direccion
def boton_2 (y):
global t0, n
if n == 200:
n = 10
else:
n = 200
t0.init(period=n, mode=Timer.PERIODIC, callback = tim)
def tim (z):
global n, servo, direccion
pwm.duty(servo)
if direccion:
servo = servo + 1
if servo > 125:
direccion = 0
else:
servo = servo - 1
if servo < 25:
direccion = 1
t0.init(period=n, mode=Timer.PERIODIC, callback = tim)
n = 200
direccion = 1
servo = 25
t0 = Timer(0)
t0.init(period=200, mode=Timer.PERIODIC, callback = tim)
push_1.irq(trigger=Pin.IRQ_FALLING, handler=boton_1)
push_2.irq(trigger=Pin.IRQ_FALLING, handler=boton_2)
while (1):
pass