Last active
February 28, 2020 20:38
-
-
Save muratsu/db8e770302b5301bfafd103690d4f7c9 to your computer and use it in GitHub Desktop.
motor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# Import required modules | |
import time | |
import RPi.GPIO as GPIO | |
# Declare the GPIO settings | |
GPIO.setmode(GPIO.BOARD) | |
# set up GPIO pins | |
GPIO.setup(7, GPIO.OUT) # Connected to PWMA | |
GPIO.setup(11, GPIO.OUT) # Connected to AIN2 | |
GPIO.setup(12, GPIO.OUT) # Connected to AIN1 | |
GPIO.setup(13, GPIO.OUT) # Connected to STBY | |
while True: | |
# Drive the motor clockwise | |
GPIO.output(12, 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) | |
# Wait 5 seconds | |
time.sleep(5) | |
# Reset all the GPIO pins by setting them to LOW | |
GPIO.output(12, 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 | |
# Drive the motor counterclockwise | |
GPIO.output(12, GPIO.LOW) # Set AIN1 | |
GPIO.output(11, GPIO.HIGH) # Set AIN2 | |
# Set the motor speed | |
GPIO.output(7, GPIO.HIGH) # Set PWMA | |
# Disable STBY (standby) | |
GPIO.output(13, GPIO.HIGH) | |
# Wait 5 seconds | |
time.sleep(5) | |
# Reset all the GPIO pins by setting them to LOW | |
GPIO.output(12, 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment