Created
July 5, 2016 22:35
-
-
Save nyboer/31855e318378bc083de551fe6305ef8a to your computer and use it in GitHub Desktop.
Simply python script to try out edge detection with NTC C.H.I.P. GPIO and buttons.
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
#use edge detection to trigger button event with CHIP_IO and Adafruit GPIO Library on Next Thing Co's C.H.I.P. | |
import time | |
import CHIP_IO.GPIO as GPIO | |
# Pin configuration. | |
pinA = "XIO-P4" | |
pinB = "XIO-P5" | |
pinC = "XIO-P6" | |
# Setup input for pin | |
GPIO.setup(pinA,GPIO.IN) | |
GPIO.setup(pinB,GPIO.IN) | |
GPIO.setup(pinC,GPIO.IN) | |
def fallcall(channel): | |
print "CALLBACK FALL" | |
def risecall(channel): | |
print "CALLBACK RISE" | |
def bothcall(channel): | |
print "CALLBACK BOTH" | |
# Setup input for pin | |
#GPIO.setup(pin,GPIO.IN) | |
GPIO.add_event_detect(pinA,GPIO.FALLING,fallcall) | |
GPIO.add_event_detect(pinB,GPIO.RISING,risecall) | |
GPIO.add_event_detect(pinC,GPIO.BOTH,bothcall) | |
# make a loop | |
try: | |
while True: | |
print "press a button..." | |
time.sleep(1) | |
except KeyboardInterrupt: | |
GPIO.cleanup() # clean up GPIO on CTRL+C exit | |
GPIO.cleanup() # clean up GPIO on normal exit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment