Add MotionSensor

This commit is contained in:
Ben Nuttall
2015-09-14 15:54:54 +01:00
parent d802e2d89a
commit f548729676
2 changed files with 11 additions and 0 deletions

View File

@@ -7,3 +7,4 @@ Abstraction classes for everyday GPIO components, based on RPi.GPIO
- LED - LED
- Buzzer - Buzzer
- Button - Button
- MotionSensor

View File

@@ -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