Esempio n. 1
0
 def test_switchbounce(self):
     self.switchcount = 0
     print "\nSwitch bounce test.  Press switch at least 10 times and count..."
     GPIO.add_event_detect(SWITCH_PIN, GPIO.FALLING, callback=self.cb, bouncetime=200)
     while self.switchcount < 10:
         time.sleep(1)
     GPIO.remove_event_detect(SWITCH_PIN)
Esempio n. 2
0
 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)
Esempio n. 3
0
 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)
Esempio n. 4
0
def testEventDetect(pin, trigger):
	switchCnt = 0	
	GPIO.setup(pin, GPIO.IN, GPIO.PUD_UP)

	GPIO.add_event_detect(pin, trigger)

	while switchCnt < 2:   
		if GPIO.event_detected(pin):
			switchCnt += 1
			print 'The event has been detected'
			print "\n value_%d = %d\n" %(pin,GPIO.input(pin))

	GPIO.remove_event_detect(pin)
Esempio n. 5
0
 def testExceptionInCallback(self):
     self.run_cb = False
     def cb(channel):
         with self.assertRaises(ZeroDivisionError):
             self.run_cb = True
             a = 1/0
     GPIO.output(LOOP_OUT, GPIO.LOW)
     GPIO.add_event_detect(LOOP_IN, GPIO.RISING, callback=cb)
     time.sleep(0.001)
     GPIO.output(LOOP_OUT, GPIO.HIGH)
     time.sleep(0.001)
     self.assertEqual(self.run_cb, True)
     GPIO.remove_event_detect(LOOP_IN)
Esempio n. 6
0
    def testAddEventCallback(self):
        def cb(channel):
            self.callback_count += 1

        # falling test
        self.callback_count = 0
        GPIO.output(LOOP_OUT, GPIO.HIGH)
        GPIO.add_event_detect(LOOP_IN, GPIO.FALLING)
        GPIO.add_event_callback(LOOP_IN, cb)
        time.sleep(0.001)
        for i in range(5):
            GPIO.output(LOOP_OUT, GPIO.LOW)
            time.sleep(0.001)
            GPIO.output(LOOP_OUT, GPIO.HIGH)
            time.sleep(0.001)
        self.assertEqual(self.callback_count, 5)
        GPIO.remove_event_detect(LOOP_IN)

        # rising test
        self.callback_count = 0
        GPIO.output(LOOP_OUT, GPIO.LOW)
        GPIO.add_event_detect(LOOP_IN, GPIO.RISING, callback=cb)
        time.sleep(0.001)
        for i in range(5):
            GPIO.output(LOOP_OUT, GPIO.HIGH)
            time.sleep(0.001)
            GPIO.output(LOOP_OUT, GPIO.LOW)
            time.sleep(0.001)
        self.assertEqual(self.callback_count, 5)
        GPIO.remove_event_detect(LOOP_IN)

        # both test
        self.callback_count = 0
        GPIO.output(LOOP_OUT, GPIO.LOW)
        GPIO.add_event_detect(LOOP_IN, GPIO.BOTH, callback=cb)
        time.sleep(0.001)
        for i in range(5):
            GPIO.output(LOOP_OUT, GPIO.HIGH)
            time.sleep(0.001)
            GPIO.output(LOOP_OUT, GPIO.LOW)
            time.sleep(0.001)
        self.assertEqual(self.callback_count, 10)
        GPIO.remove_event_detect(LOOP_IN)
Esempio n. 7
0
'''P8 P10 P12 P13 P15 P16 P22 P19 P23'''

#The following pins support the external event detected on the 40Pin Header of the BananaPro
'''P7 P8 P10 P11 P13 P15 P16 P18 P19 P21 P22 P23 P24 P26'''

testPinOnGt = 8  #For LeMaker Guitar
testPinOnBP = 18  #For BananaPro

GPIO.setmode(GPIO.BOARD)
GPIO.setup(testPinOnGt, GPIO.IN, GPIO.PUD_UP)


def testCallback(channel):
    print "running callback function", channel


GPIO.add_event_detect(testPinOnGt,
                      GPIO.RISING,
                      callback=testCallback,
                      bouncetime=300)

try:
    while True:
        time.sleep(1)
except KeyboardInterrupt:
    pass

GPIO.remove_event_detect(testPinOnGt)

GPIO.cleanup()
Esempio n. 8
0
#!/usr/bin/env python
import LMK.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)
Esempio n. 9
0
import LMK.GPIO as GPIO
import time

#The following pins support the external event detected on the 40Pin Header of the LeMake Guitar
'''P8 P10 P12 P13 P15 P16 P22 P19 P23'''

#The following pins support the external event detected on the 40Pin Header of the BananaPro
'''P7 P8 P10 P11 P13 P15 P16 P18 P19 P21 P22 P23 P24 P26'''

testPinOnGt = 8   #For LeMaker Guitar
testPinOnBP = 18  #For BananaPro

GPIO.setmode(GPIO.BOARD)
GPIO.setup(testPinOnGt, GPIO.IN, GPIO.PUD_UP)

def testCallback(channel):
	print "running callback function", channel

GPIO.add_event_detect(testPinOnGt, GPIO.RISING, callback=testCallback, bouncetime=300)

try:
	while True:
		time.sleep(1)
except KeyboardInterrupt:
	pass

GPIO.remove_event_detect(testPinOnGt)

GPIO.cleanup()