mirror of
https://github.com/KevinMidboe/python-gpiozero.git
synced 2025-10-29 17:50:37 +00:00
29
.gitignore
vendored
29
.gitignore
vendored
@@ -1 +1,28 @@
|
||||
*.pyc
|
||||
*.py[cdo]
|
||||
|
||||
# Editor detritus
|
||||
*.vim
|
||||
*.swp
|
||||
tags
|
||||
|
||||
# Packaging detritus
|
||||
*.egg
|
||||
*.egg-info
|
||||
dist
|
||||
build
|
||||
eggs
|
||||
parts
|
||||
bin
|
||||
var
|
||||
sdist
|
||||
develop-eggs
|
||||
.installed.cfg
|
||||
|
||||
# Installer logs
|
||||
pip-log.txt
|
||||
|
||||
# Unit test / coverage reports
|
||||
coverage
|
||||
.coverage
|
||||
.tox
|
||||
|
||||
|
||||
@@ -126,7 +126,7 @@ from gpio_components import MotionSensor
|
||||
pir = MotionSensor(5)
|
||||
|
||||
while True:
|
||||
if pir.motion_detected():
|
||||
if pir.motion_detected:
|
||||
print("Motion detected")
|
||||
```
|
||||
|
||||
|
||||
20
gpio_components/__init__.py
Normal file
20
gpio_components/__init__.py
Normal file
@@ -0,0 +1,20 @@
|
||||
from RPi import GPIO
|
||||
|
||||
GPIO.setmode(GPIO.BCM)
|
||||
GPIO.setwarnings(False)
|
||||
|
||||
from .input_devices import (
|
||||
InputDeviceError,
|
||||
InputDevice,
|
||||
Button,
|
||||
MotionSensor,
|
||||
LightSensor,
|
||||
TemperatureSensor,
|
||||
)
|
||||
from .output_devices import (
|
||||
OutputDevice,
|
||||
LED,
|
||||
Buzzer,
|
||||
Motor,
|
||||
)
|
||||
|
||||
@@ -2,10 +2,6 @@ from RPi import GPIO
|
||||
from w1thermsensor import W1ThermSensor
|
||||
|
||||
|
||||
GPIO.setmode(GPIO.BCM)
|
||||
GPIO.setwarnings(False)
|
||||
|
||||
|
||||
class InputDevice(object):
|
||||
def __init__(self, pin=None):
|
||||
if pin is None:
|
||||
@@ -42,8 +38,9 @@ class Button(InputDevice):
|
||||
class MotionSensor(InputDevice):
|
||||
def _is_active_with_pause(self):
|
||||
sleep(0.1)
|
||||
return self.is_active()
|
||||
return self.is_active
|
||||
|
||||
@property
|
||||
def motion_detected(self):
|
||||
n = 20
|
||||
return sum(self._is_active_with_pause() for i in range(n)) > n/2
|
||||
@@ -86,11 +83,6 @@ class LightSensor(object):
|
||||
average_value = sum(values) / len(values)
|
||||
return average_value
|
||||
|
||||
def _get_average_light_level(self, num):
|
||||
values = [self._get_light_level() for n in range(num)]
|
||||
average_value = sum(values) / len(values)
|
||||
return average_value
|
||||
|
||||
|
||||
class TemperatureSensor(W1ThermSensor):
|
||||
@property
|
||||
|
||||
@@ -1,10 +1,6 @@
|
||||
from RPi import GPIO
|
||||
|
||||
|
||||
GPIO.setmode(GPIO.BCM)
|
||||
GPIO.setwarnings(False)
|
||||
|
||||
|
||||
class OutputDevice(object):
|
||||
def __init__(self, pin):
|
||||
self.pin = pin
|
||||
|
||||
Reference in New Issue
Block a user