-
Notifications
You must be signed in to change notification settings - Fork 0
/
leds.ino
46 lines (38 loc) · 1.93 KB
/
leds.ino
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
/*
Modul LED's for ESP8266
part of Arduino Mega Server project
*/
#ifdef LEDS_FEATURE
#define R 0
#define G 1
#define B 2
byte led1[] = {4, 5, 16}; // RGB pins
byte fade = 3;
byte bright = 30;
void ledsInit() {
pinMode(led1[R], OUTPUT);
pinMode(led1[G], OUTPUT);
pinMode(led1[B], OUTPUT);
black(led1);
modulLeds = MODUL_ENABLE;
}
// set color LED
void black (byte pins[]) {analogWrite(pins[R], 0); analogWrite(pins[G], 0); analogWrite(pins[B], 0);}
void white (byte pins[], byte v) {analogWrite(pins[R], v); analogWrite(pins[G], v); analogWrite(pins[B], v);}
void red (byte pins[], byte v) {analogWrite(pins[R], v); analogWrite(pins[G], 0); analogWrite(pins[B], 0);}
void green (byte pins[], byte v) {analogWrite(pins[R], 0); analogWrite(pins[G], v); analogWrite(pins[B], 0);}
void blue (byte pins[], byte v) {analogWrite(pins[R], 0); analogWrite(pins[G], 0); analogWrite(pins[B], v);}
void yellow (byte pins[], byte v) {analogWrite(pins[R], v); analogWrite(pins[G], v); analogWrite(pins[B], 0);}
void magenta(byte pins[], byte v) {analogWrite(pins[R], v); analogWrite(pins[G], 0); analogWrite(pins[B], v);}
void cyan (byte pins[], byte v) {analogWrite(pins[R], 0); analogWrite(pins[G], v); analogWrite(pins[B], v);}
void color (byte pins[], byte r, byte g, byte b) {analogWrite(pins[R], r); analogWrite(pins[G], g); analogWrite(pins[B], b);}
void analogShow(byte pins[]) {
int r, g, b;
for (r = 0; r < 256; r++) {analogWrite(pins[R], r); delay(fade);} // blue - magenta
for (b = 255; b > 0; b--) {analogWrite(pins[B], b); delay(fade);} // magenta - red
for (g = 0; g < 256; g++) {analogWrite(pins[G], g); delay(fade);} // red - yellow
for (r = 255; r > 0; r--) {analogWrite(pins[R], r); delay(fade);} // yellow - green
for (b = 0; b < 256; b++) {analogWrite(pins[B], b); delay(fade);} // green - green/blue
for (g = 255; g > 0; g--) {analogWrite(pins[G], g); delay(fade);} // green/blue - blue
}
#endif // LEDS_FEATURE