Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # Import required modules
- import time
- import RPi.GPIO as GPIO
- # Declare the GPIO settings
- GPIO.setmode(GPIO.BOARD)
- # Set the filename and path for the sound card in use
- # (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)
- # Which one?
- #soundcard_status_file = '/proc/asound/card0/pcm0p/sub0/status'
- soundcard_status_file = '/proc/asound/card1/pcm0c/sub0/status'
- # Turn off GPIO warnings caused by us declaring our pins outside of the start_furby and stop_furby functions
- GPIO.setwarnings(False)
- def start_furby():
- # Drive the motor clockwise
- GPIO.output(16, GPIO.HIGH) # Set AIN1
- GPIO.output(11, GPIO.LOW) # Set AIN2
- # Set the motor speed
- GPIO.output(7, GPIO.HIGH) # Set PWMA
- # Disable STBY (standby)
- GPIO.output(13, GPIO.HIGH)
- def stop_furby():
- # Reset all the GPIO pins by setting them to LOW
- GPIO.output(16, GPIO.LOW) # Set AIN1
- GPIO.output(11, GPIO.LOW) # Set AIN2
- GPIO.output(7, GPIO.LOW) # Set PWMA
- GPIO.output(13, GPIO.LOW) # Set STBY
- def main():
- # Set up GPIO pins
- GPIO.setup(7, GPIO.OUT) # Connected to PWMA
- GPIO.setup(11, GPIO.OUT) # Connected to AIN2
- GPIO.setup(16, GPIO.OUT) # Connected to AIN1
- GPIO.setup(13, GPIO.OUT) # Connected to STBY
- start_furby()
- time.sleep(5)
- stop_furby()
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement