我们从Python开源项目中,提取了以下2个代码示例,用于说明如何使用gpiozero.MotionSensor()。
def __init__(self, sensor_pin=4): self.pir = MotionSensor(sensor_pin) self.led_pins = {} self.count = int(time.time()) self.pir.when_motion = self.on_when_motion self.pir.when_no_motion = self.on_when_no_motion self.audio_file_index = 0 self.led_color_index = 0 for pin in LED_PINS: self.led_pins[pin] = LED(pin) print('Artwork is watching motions...') pause()
def main(): try: counter = count(1) with MotionSensor(11) as pir: pir.when_motion = lambda: counting(counter) signal.pause() except KeyboardInterrupt: pass