-
Notifications
You must be signed in to change notification settings - Fork 0
/
Flashing_Light.py
101 lines (63 loc) · 3.01 KB
/
Flashing_Light.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# Version: FL v.0.0.5 | Last modified: 2016.12.20
# Written for KEYES KY-016
import RPi.GPIO as GPIO
from time import sleep
class LED_Control():
def __init__(self, R_pin, G_pin, B_pin, R_freq, G_freq, B_freq, R_dcycle, G_dcycle, B_dcycle):
self.__R_pin = R_pin
self.__G_pin = G_pin
self.__B_pin = B_pin
self.__R_freq = R_freq
self.__G_freq = G_freq
self.__B_freq = B_freq
self.__R_dcycle = R_dcycle
self.__G_dcycle = G_dcycle
self.__B_dcycle = B_dcycle
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
GPIO.setup(self.__R_pin, GPIO.OUT)
GPIO.setup(self.__G_pin, GPIO.OUT)
GPIO.setup(self.__B_pin, GPIO.OUT)
def flashing_light(self):
self.r = GPIO.PWM(self.__R_pin, self.__R_freq)
self.g = GPIO.PWM(self.__G_pin, self.__G_freq)
self.b = GPIO.PWM(self.__B_pin, self.__B_freq)
self.r.start(self.__R_dcycle)
self.g.start(self.__G_dcycle)
self.b.start(self.__B_dcycle)
def stop_flashing(self):
self.r.stop()
self.g.stop()
self.b.stop()
def constant_RED_light_on(self):
GPIO.output(self.__R_pin, GPIO.HIGH)
GPIO.output(self.__G_pin, GPIO.LOW)
GPIO.output(self.__B_pin, GPIO.LOW)
def constant_GREEN_light_on(self):
GPIO.output(self.__R_pin, GPIO.LOW)
GPIO.output(self.__G_pin, GPIO.HIGH)
GPIO.output(self.__B_pin, GPIO.LOW)
def constant_BLUE_light_on(self):
GPIO.output(self.__R_pin, GPIO.LOW)
GPIO.output(self.__G_pin, GPIO.LOW)
GPIO.output(self.__B_pin, GPIO.HIGH)
def constant_YELLOW_light_on(self):
GPIO.output(self.__R_pin, GPIO.HIGH)
GPIO.output(self.__G_pin, GPIO.HIGH)
GPIO.output(self.__B_pin, GPIO.LOW)
def constant_WHITE_light_on(self):
GPIO.output(self.__R_pin, GPIO.HIGH)
GPIO.output(self.__G_pin, GPIO.HIGH)
GPIO.output(self.__B_pin, GPIO.HIGH)
def constant_CYAN_light_on(self):
GPIO.output(self.__R_pin, GPIO.LOW)
GPIO.output(self.__G_pin, GPIO.HIGH)
GPIO.output(self.__B_pin, GPIO.HIGH)
def constant_MAGI_light_on(self):
GPIO.output(self.__R_pin, GPIO.HIGH)
GPIO.output(self.__G_pin, GPIO.LOW)
GPIO.output(self.__B_pin, GPIO.HIGH)
def constant_light_off(self):
GPIO.output(self.__R_pin, GPIO.LOW)
GPIO.output(self.__G_pin, GPIO.LOW)
GPIO.output(self.__B_pin, GPIO.LOW)