-
Notifications
You must be signed in to change notification settings - Fork 0
/
led.py
63 lines (52 loc) · 1 KB
/
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
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
#!/opt/kasse/venv/bin/python3
import RPi.GPIO as GPIO
class LED:
def __init__(self, r, g, b):
self.r = r
self.g = g
self.b = b
GPIO.setmode(GPIO.BCM)
GPIO.setup(r, GPIO.OUT)
GPIO.setup(g, GPIO.OUT)
GPIO.setup(b, GPIO.OUT)
def clear(self):
GPIO.output(self.r, 1)
GPIO.output(self.g, 1)
GPIO.output(self.b, 1)
def red(self):
self.clear()
GPIO.output(self.r, 0)
def green(self):
self.clear()
GPIO.output(self.g, 0)
def blue(self):
self.clear()
GPIO.output(self.b, 0)
def yellow(self):
self.clear()
GPIO.output(self.r, 0)
GPIO.output(self.g, 0)
def purple(self):
self.clear()
GPIO.output(self.r, 0)
GPIO.output(self.b, 0)
def cyan(self):
self.clear()
GPIO.output(self.g, 0)
GPIO.output(self.b, 0)
def white(self):
GPIO.output(self.r, 0)
GPIO.output(self.g, 0)
GPIO.output(self.b, 0)
"""Unittest
"""
if __name__ == '__main__':
import time
led = LED(5, 13, 6)
led.red()
time.sleep(1)
led.green()
time.sleep(1)
led.blue()
time.sleep(1)
led.clear()