-
-
Save rosterloh/1992365 to your computer and use it in GitHub Desktop.
BeagleBone GPIO with Python Test
This file contains hidden or 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 time | |
# Open up the pins and set mode in/out | |
# TODO: Error handling | |
outPin = file("/sys/class/gpio/export", "w") | |
outPin.write("%d" % (38)) | |
outPin.close() | |
outPin = file("/sys/class/gpio/gpio38/direction", "w") | |
outPin.write("out") | |
outPin.close() | |
inPin = file("/sys/class/gpio/export", "w") | |
inPin.write("%d" % (70)) | |
inPin.close() | |
inPin = file("/sys/class/gpio/gpio70/direction", "w") | |
inPin.write("in") | |
inPin.close() | |
#Open outPin for writing and inPin for reading: | |
outPin = file("/sys/class/gpio/gpio38/value", "w") | |
inPin = file("/sys/class/gpio/gpio70/value", "r") | |
try: | |
while True: | |
inPin.seek(0) | |
if inPin.read() =="1\n": | |
print "Button Pressed!\n" | |
outPin.write("1") | |
outPin.flush() | |
time.sleep(1) | |
outPin.write("0") | |
outPin.flush() | |
# Control+C will get us out of that loop and close the pins so that other apps can use: | |
except KeyboardInterrupt: | |
inPin = file("/sys/class/gpio/unexport", "w") | |
inPin.write("%d" % (38)) | |
inPin.close() | |
outPin = file("/sys/class/gpio/unexport", "w") | |
outPin.write("%d" % (70)) | |
inPin.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment