Skip to content

Commit 6ea3150

Browse files
authored
Merge pull request #126 from RaspberryPiFoundation:feature/MotionSensor
Add MotionSensor
2 parents dcd67a4 + 73ddd80 commit 6ea3150

File tree

6 files changed

+905
-478
lines changed

6 files changed

+905
-478
lines changed

docs/api.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,14 @@ Button
101101
:inherited-members:
102102
:members:
103103

104+
MotionSensor
105+
------------
106+
107+
.. autoclass:: MotionSensor
108+
:show-inheritance:
109+
:inherited-members:
110+
:members:
111+
104112
Switch
105113
------
106114

docs/examples/motion_sensor.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from picozero import MotionSensor
2+
from time import sleep
3+
4+
pir = MotionSensor(2)
5+
6+
print("PIR Motion Sensor Example")
7+
print("Waiting for motion...")
8+
9+
while True:
10+
if pir.motion_detected:
11+
print("Motion detected!")
12+
sleep(1)
13+
else:
14+
print("No motion")
15+
sleep(0.5)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from picozero import MotionSensor, pico_led
2+
from time import sleep
3+
4+
pir = MotionSensor(2)
5+
6+
# Set up event callbacks
7+
pir.when_motion = pico_led.on
8+
pir.when_no_motion = pico_led.off
9+
10+
# Keep the program running
11+
try:
12+
while True:
13+
sleep(1)
14+
except KeyboardInterrupt:
15+
print("\nShutting down...")
16+
pico_led.off() # Make sure LED is off when exiting

picozero/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
DigitalInputDevice,
2929
Switch,
3030
Button,
31+
MotionSensor,
3132

3233
AnalogInputDevice,
3334
Potentiometer,

0 commit comments

Comments
 (0)