tdrobotica

Proyecto Joystick

Dec 29th, 2021 (edited)
1,907
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.85 KB | None | 0 0
  1. from machine import ADC
  2. from machine import Pin
  3. from time import sleep
  4.  
  5. #Analog input pins
  6. joyx = ADC(Pin(39))
  7. joyy = ADC(Pin(36))
  8.  
  9. #Analog input complete range
  10. joyx.atten(ADC.ATTN_11DB)
  11. joyy.atten(ADC.ATTN_11DB)
  12.  
  13. #output pins
  14. ain1 = Pin(12, Pin.OUT)
  15. ain2 = Pin(13, Pin.OUT)
  16. bin1 = Pin(18, Pin.OUT)
  17. bin2 = Pin(19, Pin.OUT)
  18.  
  19. while True:
  20.     if joyx.read() < 1500:
  21.         ain1.off()
  22.         ain2.on()
  23.     elif joyx.read() > 2500:
  24.         ain2.off()
  25.         ain1.on()
  26.     else:
  27.         ain1.off()
  28.         ain2.off()
  29.        
  30.     if joyy.read() < 1500:
  31.         bin1.on()
  32.         bin2.off()
  33.     elif joyy.read() > 2500:
  34.         bin1.off()
  35.         bin2.on()
  36.     else:
  37.         bin1.off()
  38.         bin2.off()
  39.     x_value = joyx.read()
  40.     y_value = joyy.read()
  41.     print("El eje x: ",x_value)
  42.     sleep(1)
  43.     print("El eje y: ",y_value)
Add Comment
Please, Sign In to add comment