Python gpiozero 模块,MotionSensor() 实例源码

我们从Python开源项目中,提取了以下2个代码示例,用于说明如何使用gpiozero.MotionSensor()

项目:artwork    作者:shlinx    | 项目源码 | 文件源码
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()
项目:Sample-Code    作者:meigrafd    | 项目源码 | 文件源码
def main():
    try:
        counter = count(1)
        with MotionSensor(11) as pir:
            pir.when_motion = lambda: counting(counter)
            signal.pause()
    except KeyboardInterrupt:
        pass