Skip to content

Commit 9f7cf6a

Browse files
committed
Change Pi.GPIO to gpiozero
because it has mock factory for desktiop development. Use: export GPIOZERO_PIN_FACTORY=mock
1 parent b6c3317 commit 9f7cf6a

File tree

4 files changed

+15
-11
lines changed

4 files changed

+15
-11
lines changed

led.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
1-
import RPi.GPIO as GPIO
1+
from gpiozero import LED
22

33
class Led():
4-
_pin = 0
4+
led = None
5+
pin = 0
56
def __init__(self, pin):
6-
GPIO.setwarnings(False)
7-
GPIO.setmode(GPIO.BCM)
8-
if(pin is not None):
9-
self._pin = pin
10-
GPIO.setup(self._pin, GPIO.OUT)
7+
self.pin = pin
8+
self.led = LED(pin)
119

1210
def status(self):
13-
return GPIO.input(self._pin)
11+
if self.leds_on():
12+
return 1
13+
else:
14+
return 0
1415
def leds_on(self):
15-
return self.status() == 1
16+
return self.led.is_active
1617
def switch_leds(self, on):
1718
if(on):
18-
GPIO.output(self._pin, GPIO.HIGH)
19+
self.led.on()
1920
else:
20-
GPIO.output(self._pin, GPIO.LOW)
21+
self.led.off()

requirements-opencv.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
click==6.7
22
Flask==1.1.2
3+
gpiozero
34
itsdangerous==0.24
45
Jinja2==2.11.2
56
MarkupSafe==1.1.1

requirements-pi.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
click==6.7
22
Flask==1.1.2
3+
gpiozero
34
itsdangerous==0.24
45
Jinja2==2.11.2
56
MarkupSafe==1.1.1

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
click==6.7
22
Flask==1.1.2
3+
gpiozero
34
itsdangerous==0.24
45
Jinja2==2.11.2
56
MarkupSafe==1.1.1

0 commit comments

Comments
 (0)