def on_press(self, callback):
"""Calls the callback whenever the button is pressed.
Args:
callback: a function to call whenever the button is pressed. It should
take a single channel number. If the callback is None, the previously
registered callback, if any, is canceled.
Example:
def MyButtonPressHandler(channel):
print "button pressed: channel = %d" % channel
my_button.on_press(MyButtonPressHandler)
"""
GPIO.remove_event_detect(self.channel)
if callback is not None:
self.callback = callback
GPIO.add_event_detect(
self.channel, self.polarity, callback=self._debounce_and_callback)
评论列表
文章目录