Created
September 5, 2016 20:50
-
-
Save rxseger/cdf8f9448b82df91d39cce6f1d0c1fdf to your computer and use it in GitHub Desktop.
control 4-input H-Bridge via Raspberry Pi GPIO
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/python | |
import RPi.GPIO as GPIO | |
import sys | |
GPIO.setmode(GPIO.BOARD) | |
K1 = 38 # G20 | |
K2 = 7 # G4 | |
K3 = 36 # G16 | |
K4 = 40 # G21 | |
GPIO.setwarnings(False) | |
GPIO.setup([K1, K2, K3, K4], GPIO.OUT, initial=GPIO.LOW) | |
GPIO.output(K1, False) | |
GPIO.output(K2, False) | |
GPIO.output(K3, False) | |
GPIO.output(K4, False) | |
if len(sys.argv) < 2: | |
print "usage: %s [coast|forward|reverse|brake|brake2]" % (sys.argv[0],) | |
raise SystemExit | |
if sys.argv[1] == 'coast': | |
pass | |
elif sys.argv[1] == 'forward': | |
GPIO.output(K1, True) | |
GPIO.output(K4, True) | |
elif sys.argv[1] == 'reverse': | |
GPIO.output(K3, True) | |
GPIO.output(K2, True) | |
elif sys.argv[1] == 'brake': | |
GPIO.output(K2, True) | |
GPIO.output(K4, True) | |
elif sys.argv[1] == 'brake2': | |
GPIO.output(K1, True) | |
GPIO.output(K3, True) | |
else: | |
print "unrecognized: %s" % (sys,argv[1],) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment