Advertisement
Guest User

Untitled

a guest
Sep 20th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. import RPi.GPIO as GPIO #Importamos la libreria RPi.GPIO
  2. import time #Importamos time para poder usar time.sleep
  3.  
  4. GPIO.setmode(GPIO.BOARD) #Ponemos la Raspberry en modo BOARD
  5. GPIO.setup(21,GPIO.OUT) #Ponemos el pin 21 como salida
  6. p = GPIO.PWM(21,50) #Ponemos el pin 21 en modo PWM y enviamos 50 pulsos por segundo
  7. p.start(7.5) #Enviamos un pulso del 7.5% para centrar el servo
  8.  
  9. try:
  10. while True: #iniciamos un loop infinito
  11.  
  12. p.ChangeDutyCycle(4.5) #Enviamos un pulso del 4.5% para girar el servo hacia la izquierda
  13. time.sleep(0.5) #pausa de medio segundo
  14. p.ChangeDutyCycle(10.5) #Enviamos un pulso del 10.5% para girar el servo hacia la derecha
  15. time.sleep(0.5) #pausa de medio segundo
  16. p.ChangeDutyCycle(7.5) #Enviamos un pulso del 7.5% para centrar el servo de nuevo
  17. time.sleep(0.5) #pausa de medio segundo
  18.  
  19. except KeyboardInterrupt: #Si el usuario pulsa CONTROL+C entonces...
  20. p.stop() #Detenemos el servo
  21. GPIO.cleanup() #Limpiamos los pines GPIO de la Raspberry y cerramos el script
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement