-
Notifications
You must be signed in to change notification settings - Fork 0
/
rgb_led.py
34 lines (31 loc) · 1.11 KB
/
rgb_led.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
from pins import RED, BLUE, GREEN
from machine import Pin
import __main__ as m
class RGB_LED():
def __init__(self, init = 'off'):
self.pins = [Pin(int(i), Pin.OUT) for i in [RED,BLUE,GREEN]]
self.colors ={'off' : [0,0,0],
'white' : [1,1,1],
'red' : [1,0,0],
'green' : [0,1,0],
'blue' : [0,0,1],
'yellow' : [1,1,0],
'cyan' : [0,1,1],
'magneta' : [1,0,1]
}
self.color(init)
def color(self, rgb):
try:
for col, setting in enumerate(self.colors[rgb]):
self.pins[col].value( int( not setting) )
try: # here injected exception
m.states.RF_positions['color'] = rgb
m.states.previous_color = rgb
except: pass
return 'rgb ' + rgb
except Exception as e:
print (e)
return str(e)
def api(self, value):
"for http_control"
return self.color(value[0].lower())