File tree Expand file tree Collapse file tree 6 files changed +940
-477
lines changed Expand file tree Collapse file tree 6 files changed +940
-477
lines changed Original file line number Diff line number Diff 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+
104112Switch
105113------
106114
Original file line number Diff line number Diff line change 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 )
Original file line number Diff line number Diff line change 1+ from picozero import MotionSensor , LED
2+ from time import sleep
3+
4+ pir = MotionSensor (2 )
5+ led = LED (14 )
6+
7+ print ("Advanced PIR Motion Sensor Example" )
8+ print ("Using event callbacks for motion detection..." )
9+
10+
11+ def motion_detected ():
12+ print ("🚶 Motion detected!" )
13+ led .on () # Turn on LED when motion detected
14+
15+
16+ def no_motion ():
17+ print ("😴 No motion detected" )
18+ led .off () # Turn off LED when no motion
19+
20+
21+ # Set up event callbacks
22+ pir .when_motion = motion_detected
23+ pir .when_no_motion = no_motion
24+
25+ # Keep the program running
26+ try :
27+ while True :
28+ sleep (1 )
29+ except KeyboardInterrupt :
30+ print ("\n Shutting down..." )
31+ led .off () # Make sure LED is off when exiting
Original file line number Diff line number Diff line change 2828 DigitalInputDevice ,
2929 Switch ,
3030 Button ,
31+ MotionSensor ,
3132
3233 AnalogInputDevice ,
3334 Potentiometer ,
You can’t perform that action at this time.
0 commit comments