本文整理汇总了Python中LMK.GPIO.add_event_detect方法的典型用法代码示例。如果您正苦于以下问题:Python GPIO.add_event_detect方法的具体用法?Python GPIO.add_event_detect怎么用?Python GPIO.add_event_detect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LMK.GPIO
的用法示例。
在下文中一共展示了GPIO.add_event_detect方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_switchbounce
# 需要导入模块: from LMK import GPIO [as 别名]
# 或者: from LMK.GPIO import add_event_detect [as 别名]
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)
示例2: test_event_detected
# 需要导入模块: from LMK import GPIO [as 别名]
# 或者: from LMK.GPIO import add_event_detect [as 别名]
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)
示例3: testRisingEventDetected
# 需要导入模块: from LMK import GPIO [as 别名]
# 或者: from LMK.GPIO import add_event_detect [as 别名]
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)
示例4: testEventDetect
# 需要导入模块: from LMK import GPIO [as 别名]
# 或者: from LMK.GPIO import add_event_detect [as 别名]
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)
示例5: testExceptionInCallback
# 需要导入模块: from LMK import GPIO [as 别名]
# 或者: from LMK.GPIO import add_event_detect [as 别名]
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)
示例6: testAddEventCallback
# 需要导入模块: from LMK import GPIO [as 别名]
# 或者: from LMK.GPIO import add_event_detect [as 别名]
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)
示例7: my_callback
# 需要导入模块: from LMK import GPIO [as 别名]
# 或者: from LMK.GPIO import add_event_detect [as 别名]
import LMK.GPIO as GPIO
import time
#PIN_NUM = 24
#GPIO.setmode(GPIO.BOARD)
#GPIO.setup(PIN_NUM,GPIO.IN,GPIO.PUD_DOWN)
GPIO.setmode(GPIO.RAW)
GPIO.setup(GPIO.PI+10,GPIO.IN,GPIO.PUD_DOWN)
print "The value of Pin %d is %d" %(GPIO.PI+10,GPIO.input(GPIO.PI+10))
def my_callback(channel):
print "Callback trigger %d" %channel
print "Now value of the Pin is %d" %(GPIO.input(GPIO.PI+10))
print "Click Ctr + C to exit"
GPIO.add_event_detect(GPIO.PI+10,GPIO.RISING,callback = my_callback,bouncetime = 300)
try:
while True:
time.sleep(0.1)
except KeyboardInterrupt:
pass
GPIO.cleanup()
示例8:
# 需要导入模块: from LMK import GPIO [as 别名]
# 或者: from LMK.GPIO import add_event_detect [as 别名]
#!/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)
示例9: print
# 需要导入模块: from LMK import GPIO [as 别名]
# 或者: from LMK.GPIO import add_event_detect [as 别名]
else:
print("I2C PCF8591 should read from channel [0 | 1 | 2 | 3]")
if DA and Addons["PCF8591"]:
out = int(DA[0])
IOboard.writePCF8591(out)
outV = 3.3*out/255
print("I2C PCF8591: analog output: {0} voltage.".format(outV))
sendCmd("sensor-update writePCF8591 %.2f" % (outV))
if Sound:
soundPin = int(Sound[0])
try:
GPIO.setup(soundPin, GPIO.IN, GPIO.PUD_UP)
print("Sound detect on GPIO %d is %d" %(soundPin, GPIO.input(soundPin)))
GPIO.add_event_detect(soundPin,GPIO.RISING,callback = soundDetect,bouncetime = 300)
except:
print("Failed to setup the Sound sensor")
if Touch:
touchPin = int(Touch[0])
try:
GPIO.setup(touchPin, GPIO.IN, GPIO.PUD_DOWN)
print("Touch detect on GPIO %d is %d" %(touchPin, GPIO.input(touchPin)))
Addons["TouchSensor"] = True
except:
print("Failed to setup the Touch sensor")
if Tilt:
tiltPin = int(Tilt[0])
示例10: testEventOnOutput
# 需要导入模块: from LMK import GPIO [as 别名]
# 或者: from LMK.GPIO import add_event_detect [as 别名]
def testEventOnOutput(self):
with self.assertRaises(RuntimeError):
GPIO.add_event_detect(LOOP_OUT, GPIO.FALLING)
示例11: testHighLowEvent
# 需要导入模块: from LMK import GPIO [as 别名]
# 或者: from LMK.GPIO import add_event_detect [as 别名]
def testHighLowEvent(self):
with self.assertRaises(ValueError):
GPIO.add_event_detect(LOOP_IN, GPIO.LOW)
with self.assertRaises(ValueError):
GPIO.add_event_detect(LOOP_IN, GPIO.HIGH)
示例12: testCallback
# 需要导入模块: from LMK import GPIO [as 别名]
# 或者: from LMK.GPIO import add_event_detect [as 别名]
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()
示例13: my_callback
# 需要导入模块: from LMK import GPIO [as 别名]
# 或者: from LMK.GPIO import add_event_detect [as 别名]
PIN_NUM = 24
GPIO.setmode(GPIO.BCM)
#GPIO.setmode(GPIO.BOARD)
GPIO.setup(PIN_NUM,GPIO.IN,GPIO.PUD_UP)
print "The value of Pin %d is %d" %(PIN_NUM,GPIO.input(PIN_NUM))
def my_callback(channel):
print "The value of Pin %d is %d" %(PIN_NUM,GPIO.input(PIN_NUM))
print "Callback trigger %d" %channel
print "Now value of the Pin is %d" %(GPIO.input(PIN_NUM))
print "Click Ctr + C to exit"
GPIO.add_event_detect(PIN_NUM,GPIO.RISING,callback = my_callback,bouncetime = 300)
print "The value of Pin %d is %d" %(PIN_NUM,GPIO.input(PIN_NUM))
try:
while True:
time.sleep(0.1)
except KeyboardInterrupt:
pass
GPIO.cleanup()