mirror of
https://github.com/KevinMidboe/python-gpiozero.git
synced 2025-10-29 17:50:37 +00:00
Add MotionSensor
This commit is contained in:
@@ -7,3 +7,4 @@ Abstraction classes for everyday GPIO components, based on RPi.GPIO
|
|||||||
- LED
|
- LED
|
||||||
- Buzzer
|
- Buzzer
|
||||||
- Button
|
- Button
|
||||||
|
- MotionSensor
|
||||||
|
|||||||
@@ -37,5 +37,15 @@ class Button(InputDevice):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class MotionSensor(InputDevice):
|
||||||
|
def _is_active_with_pause(self):
|
||||||
|
sleep(0.1)
|
||||||
|
return self.is_active()
|
||||||
|
|
||||||
|
def motion_detected(self):
|
||||||
|
n = 20
|
||||||
|
return sum(self._is_active_with_pause() for i in range(n)) > n/2
|
||||||
|
|
||||||
|
|
||||||
class InputDeviceError(Exception):
|
class InputDeviceError(Exception):
|
||||||
pass
|
pass
|
||||||
|
|||||||
Reference in New Issue
Block a user