from machine import Pin, PWM, Timer
pwm = PWM(Pin(23),freq=50)
led_1 = Pin(22, Pin.OUT)
led_2 = Pin(21, Pin.OUT)
led_3 = Pin(19, Pin.OUT)
led_4 = Pin(18, Pin.OUT)
led_5 = Pin(5, Pin.OUT)
led_6 = Pin(17, Pin.OUT)
push_1 = Pin(12,Pin.IN,Pin.PULL_UP)
push_2 = Pin(14,Pin.IN,Pin.PULL_UP)
def tim (x):
global direccion, servo
pwm.duty(servo)
if direccion:
servo = servo + 1
if servo > 125:
led_1.value(1)
led_2.value(1)
led_3.value(1)
led_4.value(0)
led_5.value(0)
led_6.value(0)
direccion = 0
else:
servo = servo - 1
if servo < 25:
led_4.value(1)
led_5.value(1)
led_6.value(1)
led_1.value(0)
led_2.value(0)
led_3.value(0)
direccion = 1
t0.init(period = vel, mode = Timer.PERIODIC, callback = tim)
def interrupcion (y):
global vel, t0
if vel == 100:
vel = 50
else:
vel = 100
t0.init(period = vel, mode = Timer.PERIODIC, callback = tim)
def cambio (z):
global direccion
direccion = not direccion
direccion = 1
servo = 25
vel = 50
t0 = Timer (0)
t0.init(period = 100, mode = Timer.PERIODIC, callback = tim)
push_1.irq(trigger = Pin.IRQ_FALLING, handler = interrupcion)
push_2.irq(trigger = Pin.IRQ_FALLING, handler = cambio)
while(1):
pass