本文整理汇总了Python中LMK.GPIO.add_event_callback方法的典型用法代码示例。如果您正苦于以下问题:Python GPIO.add_event_callback方法的具体用法?Python GPIO.add_event_callback怎么用?Python GPIO.add_event_callback使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LMK.GPIO
的用法示例。
在下文中一共展示了GPIO.add_event_callback方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testAddEventCallback
# 需要导入模块: from LMK import GPIO [as 别名]
# 或者: from LMK.GPIO import add_event_callback [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)