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()
python类MotionSensor()的实例源码
def main():
try:
counter = count(1)
with MotionSensor(11) as pir:
pir.when_motion = lambda: counting(counter)
signal.pause()
except KeyboardInterrupt:
pass