-
Notifications
You must be signed in to change notification settings - Fork 0
/
outreachLEDs.ino
188 lines (172 loc) · 3.64 KB
/
outreachLEDs.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
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
#include <FastLED.h>
#define LED_PIN 6
#define NUM_LEDS 142
#define BRIGHTNESS 255
#define LED_TYPE NEOPIXEL
CRGB leds[NUM_LEDS];
int forwardPin = 2;
int backwardsPin = 4;
int effect = 0;
void setup(){
pinMode(forwardPin, INPUT);
pinMode(backwardsPin, INPUT);
}
void loop(){
if(digitalRead(forwardPin) == HIGH){
effect++;
}
else if (digitalRead(backwardsPin) == HIGH){
effect--;
}
switch(effect){
case 0:
rainbowDouble(30);
break;
case 1:
break;
nightRiderSides(CRGB(0, 0, 255), CRGB(0,0,0), 5, 10, 0);
case 2:
nightRiderSides(CRGB(255, 0, 0), CRGB(0,0,0), 5, 10, 0);
break;
}
}
void setAll(CRGB c) {
for (int i = 0; i < NUM_LEDS; i++) {
leds[i] = c;
}
FastLED.show();
}
void setDoubleSide(int i, CRGB c) {
if (i < 23) {
// Bottom
leds[22-i] = c;
leds[23+i] = c;
} else if (i < 71) {
// Top
leds[142-i+22] = c;
leds[46+i-23] = c;
}
FastLED.show();
}
void nightRiderSidesOneWay(CRGB c, CRGB c2, int len, int delayTime) {
int i=0;
for (int i=0; i < NUM_LEDS/2; i++) { // Forward
leds[i] = c;
leds[(NUM_LEDS/2) + i] = c;
if (i - len >= 0) {
leds[i - len] = c2;
leds[((NUM_LEDS/2) + i) - len] = c2;
}
FastLED.show();
delay(delayTime);
}
for (int i = len; i >= 0; i--) {
leds[NUM_LEDS - i] = c2;
leds[(NUM_LEDS/2) - i] = c2;
FastLED.show();
delay(delayTime);
}
}
/**
* Nightrider effect
* CRGB c - color
* CRGB c2 - background color
* int len - length
* int delayTime - delay time
* int dir - direction
* 0 = both ways
* 1 = up
* 2 = down
*/
void nightRiderSides(CRGB c, CRGB c2, int len, int delayTime, int dir) {
if (dir == 0 || dir == 1) {
// Up
for (int i = 0; i < NUM_LEDS/2; i++) {
setDoubleSide(i, c);
if (i > len-1) {
setDoubleSide(i-len, c2);
}
delay(delayTime);
}
}
if (dir == 0 || dir == 2) {
// Down
for (int i = 0; i < NUM_LEDS/2; i++) {
setDoubleSide((NUM_LEDS/2) - i, c);
if ((NUM_LEDS/2) - i > len-1) {
setDoubleSide((NUM_LEDS/2) - i + len, c2);
}
delay(delayTime);
}
}
}
void rainbowSingle(uint8_t wait) {
uint16_t i, j;
for(j=0; j<256; j++) {
for(i=0; i<NUM_LEDS; i++) {
leds[i] = Wheel((i+j) & 255);
}
FastLED.show();
delay(wait);
}
}
void rainbowDouble(uint8_t wait) {
uint16_t i, j;
for(j=0; j<256; j++) {
for(i=0; i<NUM_LEDS/2; i++) {
setDoubleSide(i, Wheel((i+j) & 255));
}
FastLED.show();
delay(wait);
}
}
CRGB Wheel(byte WheelPos) {
WheelPos = 255 - WheelPos;
if(WheelPos < 85) {
return CRGB(255 - WheelPos * 3, 0, WheelPos * 3);
}
if(WheelPos < 170) {
WheelPos -= 85;
return CRGB(0, WheelPos * 3, 255 - WheelPos * 3);
}
WheelPos -= 170;
return CRGB(WheelPos * 3, 255 - WheelPos * 3, 0);
}
void nightRider(CRGB c, CRGB c2, int len, int delayTime) {
int i=0;
for (int i=0; i<NUM_LEDS; i++) { //FORWARD
leds[i] = c;
if (i-len >= 0) {
leds[i-len] = c2;
}
FastLED.show();
delay(delayTime);
}
for (int i=0; i<NUM_LEDS; i++) { //BACKWARD
leds[NUM_LEDS-i] = c;
if ((NUM_LEDS-i) <= NUM_LEDS-len) {
leds[(NUM_LEDS-i) + len - 1] = c2;
}
FastLED.show();
delay(delayTime);
}
}
CRGB wheel(int WheelPos, int dim) {
CRGB color;
if (85 > WheelPos) {
color.r=0;
color.g=WheelPos * 3/dim;
color.b=(255 - WheelPos * 3)/dim;;
}
else if (170 > WheelPos) {
color.r=WheelPos * 3/dim;
color.g=(255 - WheelPos * 3)/dim;
color.b=0;
}
else {
color.r=(255 - WheelPos * 3)/dim;
color.g=0;
color.b=WheelPos * 3/dim;
}
return color;
}