-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkit11588.py
70 lines (60 loc) · 2.33 KB
/
kit11588.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import RPi.GPIO as GPIO
import time
class led_breakout_kit11588():
'''
'''
status = {'red' : False, 'green' : False, 'blue' : False}
# init pins
_pin_led_blue = 18
_pin_led_red = 23
_pin_led_green = 24
def __init__(self, status=status):
self.status = status
self.on_activate()
self.set_led({'all':False})
def on_activate(self):
''' Init the device hardware
'''
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(self._pin_led_blue, GPIO.OUT)
GPIO.setup(self._pin_led_red, GPIO.OUT)
GPIO.setup(self._pin_led_green, GPIO.OUT)
def get_status(self):
''' Return the status dict of the LEDs
'''
return self.status
def set_led(self, new_status_dict):
''' Update the LED status dict
'''
for colour in new_status_dict:
if colour == 'red':
if new_status_dict[colour] is True:
GPIO.output(self._pin_led_red, GPIO.HIGH)
self.status['red'] = True
else:
GPIO.output(self._pin_led_red, GPIO.LOW)
self.status['red'] = False
elif colour == 'green':
if new_status_dict[colour] is True:
GPIO.output(self._pin_led_green, GPIO.HIGH)
self.status['green'] = True
else:
GPIO.output(self._pin_led_green, GPIO.LOW)
self.status['green'] = False
elif colour == 'blue':
if new_status_dict[colour] is True:
GPIO.output(self._pin_led_blue, GPIO.HIGH)
self.status['blue'] = True
else:
GPIO.output(self._pin_led_blue, GPIO.LOW)
self.status['blue'] = False
elif colour == 'all':
if new_status_dict[colour] is True:
GPIO.output(self._pin_led_red, GPIO.HIGH)
GPIO.output(self._pin_led_green, GPIO.HIGH)
GPIO.output(self._pin_led_blue, GPIO.HIGH)
else:
GPIO.output(self._pin_led_red, GPIO.LOW)
GPIO.output(self._pin_led_green, GPIO.LOW)
GPIO.output(self._pin_led_blue, GPIO.LOW)