from machine import Pin, ADC, PWM, UART
from time import sleep
import utime
uart = machine.UART(2, 115200)
button = Pin(14, Pin.IN)
button2 = Pin(13, Pin.IN)
sw1 = ADC(Pin(35))
vx1 = ADC(Pin(32))
vy1 = ADC(Pin(33))
sw2 = ADC(Pin(25))
vx2 = ADC(Pin(26))
vy2 = ADC(Pin(27))
#RESOLUCION(EL RANGO QUE APARECE)
vx1.width(ADC.WIDTH_10BIT)
vx2.width(ADC.WIDTH_10BIT)
vy1.width(ADC.WIDTH_10BIT)
vy2.width(ADC.WIDTH_10BIT)
AUX = 0
while True:
sleep(0.1)
Valorx1 = vx1.read()
Valory1 = vy1.read()
if Valorx1 >=900:
uart.write("A203")
print("A203")
if Valorx1 <=300:
uart.write("D203")
print("D203")
if Valory1 >=900:
uart.write("A303")
print("A303")
if Valory1 <=300:
uart.write("D303")
print("D303")
Valorx2 = vx2.read()
Valory2 = vy2.read()
if AUX == 0:
if Valorx2 >=900:
uart.write("A403")
print("A403")
if Valorx2 <=300:
uart.write("D403")
print("D403")
if Valory2 >=900:
uart.write("A503")
print("A503")
if Valory2 <=300:
uart.write("D503")
print("D503")
if AUX ==1:
if Valorx2 >=900:
uart.write("A103")
print("A103")
if Valorx2 <=300:
uart.write("D103")
print("D103")
print("AUX ", AUX)
if (button.value()):
AUX = 1
if (button2.value()):
AUX = 0