Advertisement
Guest User

furby_motor_test.py

a guest
Dec 17th, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.48 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. # Import required modules
  4. import time
  5. import RPi.GPIO as GPIO
  6.  
  7. # Declare the GPIO settings
  8. GPIO.setmode(GPIO.BOARD)
  9.  
  10. # Set the filename and path for the sound card in use
  11. # (See: https://howchoo.com/g/mmnhmti2zjz/how-to-detect-that-audio-is-currently-being-output-in-linux-and-use-it-to-call-a-program#create-an-audio-output-monitor-script)
  12.  
  13. # Which one?
  14. #soundcard_status_file = '/proc/asound/card0/pcm0p/sub0/status'
  15. soundcard_status_file = '/proc/asound/card1/pcm0c/sub0/status'
  16.  
  17. # Turn off GPIO warnings caused by us declaring our pins outside of the start_furby and stop_furby functions
  18. GPIO.setwarnings(False)
  19.  
  20. def start_furby():
  21.     # Drive the motor clockwise
  22.     GPIO.output(16, GPIO.HIGH) # Set AIN1
  23.     GPIO.output(11, GPIO.LOW) # Set AIN2
  24.  
  25.     # Set the motor speed
  26.     GPIO.output(7, GPIO.HIGH) # Set PWMA
  27.  
  28.     # Disable STBY (standby)
  29.     GPIO.output(13, GPIO.HIGH)
  30.  
  31. def stop_furby():
  32.     # Reset all the GPIO pins by setting them to LOW
  33.     GPIO.output(16, GPIO.LOW) # Set AIN1
  34.     GPIO.output(11, GPIO.LOW) # Set AIN2
  35.     GPIO.output(7, GPIO.LOW) # Set PWMA
  36.     GPIO.output(13, GPIO.LOW) # Set STBY
  37.  
  38. def main():
  39.     # Set up GPIO pins
  40.     GPIO.setup(7, GPIO.OUT) # Connected to PWMA
  41.     GPIO.setup(11, GPIO.OUT) # Connected to AIN2
  42.     GPIO.setup(16, GPIO.OUT) # Connected to AIN1
  43.     GPIO.setup(13, GPIO.OUT) # Connected to STBY
  44.  
  45.     start_furby()
  46.     time.sleep(5)
  47.     stop_furby()
  48.  
  49. if __name__ == '__main__':
  50.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement