from machine import Pin, PWM, ADC, Timer
R = PWM(Pin(22), freq=500)
G = PWM(Pin(21), freq=500)
B = PWM(Pin(19), freq=500)
servo_uno = PWM(Pin(23), freq=50)
servo_dos = PWM(Pin(18), freq=50)
vertical = ADC(Pin(32))
horizontal = ADC(Pin(33))
push = Pin(14,Pin.IN,Pin.PULL_UP)
def colores (r,g,b):
R.duty(r)
G.duty(g)
B.duty(b)
return (r,g,b)
def interrupcion (x):
global freezer
freezer = not freezer
def time (y):
global rojo, verde, azul, freezer, luz
if freezer:
return
if luz == rojo:
luz = verde
elif luz == verde:
luz = azul
else:
luz = rojo
luz = (0, 0, 0)
freezer = 0
rojo = colores(1023, 0, 0)
verde = colores(0, 1023, 0)
azul = colores(0, 0, 1023)
vertical.width(ADC.WIDTH_9BIT)
vertical.atten(ADC.ATTN_11DB)
horizontal.width(ADC.WIDTH_9BIT)
horizontal.atten(ADC.ATTN_11DB)
push.irq(trigger=Pin.IRQ_FALLING, handler=interrupcion)
t0 = Timer (0)
t0.init(period=500, mode=Timer.PERIODIC, callback = time)
while(1):
w = vertical.read()
w_i = ((w)*(125-25)/511)+25
servo_uno.duty(int(w_i))
t = horizontal.read()
t_1 =((t)*(125-25)/511)+25
servo_dos.duty(int(t_1))
#LE ALTA MODIFICAR AL CODIGO PARA QUE FUNCIONE PERFECTAMENTE
#COMO POR EJEMPLO LOS COLORES DEL RGB Y EL INTERRUPTOR