Skip to content

Instantly share code, notes, and snippets.

@nyboer
Created July 5, 2016 22:35
Show Gist options
  • Save nyboer/31855e318378bc083de551fe6305ef8a to your computer and use it in GitHub Desktop.
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.
#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