Advertisement
Guest User

Untitled

a guest
May 8th, 2020
26
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import RPi.GPIO as GPIO
  2. from time import sleep
  3.  
  4. # Pins for Motor Driver Inputs
  5. sleeper = 21
  6. motor=12
  7. GPIO.setmode(GPIO.BCM)
  8. GPIO.setup(motor,GPIO.OUT)
  9. GPIO.setup(sleeper,GPIO.OUT) # All pins as Outputs
  10. pwm=GPIO.PWM(motor,100) # configuring Enable pin for PWM
  11. pwm.start(0)
  12. def setup():
  13.  
  14. def loop():
  15. # Going forwards
  16. pwm.ChangeDutyCycle(50)
  17. sleep(10)
  18. pwm.ChangeDutyCycle(100)
  19. sleep(5)
  20. destroy();
  21. def destroy():
  22. GPIO.cleanup()
  23. pwm.ChangeDutyCycle(0)
  24. GPIO.output(sleeper,GPIO.LOW)
  25.  
  26. if __name__ == '__main__': # Program start from here
  27. setup()
  28. try:
  29. loop()
  30. except KeyboardInterrupt:
  31. GPIO.output(sleeper,GPIO.LOW)
  32. pwm.ChangeDutyCycle(0)
  33. destroy()
Advertisement
RAW Paste Data Copied
Advertisement