我们从Python开源项目中,提取了以下1个代码示例,用于说明如何使用RPi.GPIO.add_event_callback()。
def __init__(self): ''' initialize the pin for the anemometer sensor ''' self.SENSOR_PIN = 4 self.count = 0 # tell the GPIO module that we want to use the chip's pin numbering scheme GPIO.setmode(GPIO.BCM) # setup pin as an input with pullup GPIO.setup(self.SENSOR_PIN, GPIO.IN, pull_up_down=GPIO.PUD_UP) # threaded event, to detect voltage falling on anemometer # bouncetime is in ms - edges within this time will be ignored GPIO.add_event_detect(self.SENSOR_PIN, GPIO.FALLING, bouncetime=30) self.starttime = time.time() # deal with events by calling a function GPIO.add_event_callback(self.SENSOR_PIN, self.inputEventHandler)