def testRisingEventDetected(self): GPIO.output(LOOP_OUT, GPIO.LOW) GPIO.add_event_detect(LOOP_IN, GPIO.RISING) time.sleep(0.001) self.assertEqual(GPIO.event_detected(LOOP_IN), False) GPIO.output(LOOP_OUT, GPIO.HIGH) time.sleep(0.001) self.assertEqual(GPIO.event_detected(LOOP_IN), True) GPIO.output(LOOP_OUT, GPIO.LOW) time.sleep(0.001) self.assertEqual(GPIO.event_detected(LOOP_IN), False) GPIO.remove_event_detect(LOOP_IN)
def test_event_detected(self): self.switchcount = 0 print "\nGPIO.event_detected() switch bounce test. Press switch at least 10 times and count..." GPIO.add_event_detect(SWITCH_PIN, GPIO.FALLING, bouncetime=200) while self.switchcount < 10: if GPIO.event_detected(SWITCH_PIN): self.switchcount += 1 print 'Button press',self.switchcount GPIO.remove_event_detect(SWITCH_PIN)
#!/usr/bin/env python import RaPi.GPIO as GPIO import time from threading import Timer SWITCH_PIN = 18 GPIO.setmode(GPIO.BOARD) GPIO.setup(SWITCH_PIN,GPIO.IN,GPIO.PUD_UP) print "\n value_%d = %d\n" %(SWITCH_PIN,GPIO.input(SWITCH_PIN)) GPIO.add_event_detect(SWITCH_PIN, GPIO.RISING,bouncetime=200) # add rising edge detection on a channel switchcount = 0 while switchcount < 2: if GPIO.event_detected(SWITCH_PIN): switchcount += 1 print 'Button pressed',switchcount print "\n value_%d = %d\n" %(SWITCH_PIN,GPIO.input(SWITCH_PIN)) GPIO.remove_event_detect(SWITCH_PIN)