-
Notifications
You must be signed in to change notification settings - Fork 0
/
rgb.py
63 lines (42 loc) · 1.36 KB
/
rgb.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
class RGB_led:
def __init__(self, gpio_object, r, g, b):
self.__red_pin = r
self.__green_pin = g
self.__blue_pin = b
self.__outputs = [self.__red_pin, self.__blue_pin, self.__green_pin]
self.__board = gpio_object
self.__setup_pins()
def __setup_pins(self):
print('DEBUGGING: Setting up outputs')
for pin in self.__outputs:
self.__board.GPIO.setup(pin, self.__board.GPIO.OUT)
def red_on(self):
'''red led turns on'''
self.turn_off()
self.__board.GPIO.output(self.__red_pin, self.__board.GPIO.HIGH)
def green_on(self):
'''green led turns on'''
self.turn_off()
self.__board.GPIO.output(self.__green_pin, self.__board.GPIO.HIGH)
def blue_on(self):
'''blue led turns on'''
self.turn_off()
self.__board.GPIO.output(self.__blue_pin, self.__board.GPIO.HIGH)
def turn_off(self):
'''turns all the leds off before'''
for pin in self.__outputs:
self.__board.GPIO.output(pin, self.__board.GPIO.LOW)
if __name__ == "__main__":
from board import Board
from time import sleep
rpi = Board()
led = RGB_led(rpi, 20, 21, 16)
led.red_on()
sleep(3)
led.turn_off()
led.green_on()
sleep(3)
led.turn_off()
led.blue_on()
sleep(3)
led.turn_off()