-
Notifications
You must be signed in to change notification settings - Fork 0
/
stripfirmware.ino
252 lines (199 loc) · 5.96 KB
/
stripfirmware.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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
#include <FastLED.h>
#include <EEPROM.h>
#include "definitions.h";
#include "memory.h";
#define NUM_LEDS 12
#define DATA_PIN 7
CRGB leds[NUM_LEDS];
//---------------------------------------Notes---------------------------------------//
/*
By using the colour method with NUM_LEDS, you will set all LEDS to the
given colour
*/
//-----------------------------------------------------------------------------------//
//----------------------------Global variables----------------------------------//
int brightness = DEFAULT_BRIGHTNESS;
int current_colour = DEFAULT_COLOUR;
volatile int current_mode = DEFAULT_MODE;
int previousMode = 0;
int time = millis();
//-----------------------------------------------------------------------------------//
//--------------------------------Function Definitions-------------------------------//
void colour(int led = NUM_LEDS, int color = DEFAULT_COLOUR);
void setBrightness(int value = DEFAULT_BRIGHTNESS);
void fadeIn(int delayTime = DEFAULT_FADE_TIME);
void fadeOut(int delayTime = DEFAULT_FADE_TIME);
void breathe(int delayTime = DEFAULT_FADE_TIME);
void slideRight(int col = DEFAULT_COLOUR,int slideDelay = DEFAULT_SLIDE_DELAY);
void slideLeft(int col = DEFAULT_COLOUR,int slideDelay = DEFAULT_SLIDE_DELAY);
void eachRandomLed(int delayTime = DEFAULT_SLIDE_DELAY,int color[] = fullColourArray);
void switchColour(int delayTime = DEFAULT_SWITCH_DELAY,int color = randomColour());
void nightRider(int slideDelay = DEFAULT_SLIDE_DELAY);
void strobe(int color = current_colour, int delayTime = DEFAULT_SWITCH_DELAY);
//-----------------------------------------------------------------------------------//
void setup() {
Serial.begin(9600);
LEDS.addLeds<WS2812,DATA_PIN,RGB>(leds,NUM_LEDS);
blank();
delay(SAFETY_DELAY);
setBrightness();
// colour(NUM_LEDS,White);
pinMode(3, INPUT_PULLUP);
pinMode(2,INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(3), modeDown, LOW);
attachInterrupt(digitalPinToInterrupt(2), modeUp, LOW);
}
void loop() {
eachRandomLed(DEFAULT_SLIDE_DELAY,testarr);
}
void modeUp(){
Serial.print("Mode is ");
Serial.print(current_mode);
if (abs(time - millis()) < 1000){
return -1;
}
else {
time = millis();
}
current_mode++;
if (current_mode > 5) {
current_mode = 1;
}
Serial.print(" and is now ");
Serial.println(current_mode);
}
void modeDown(){
Serial.print("Mode is ");
Serial.print(current_mode);
if (millis() < time + 1000){
return -1;
}
else {
time = millis();
}
current_mode--;
if (current_mode < 1) {
current_mode = 4;
}
Serial.print(" and is now ");
Serial.println(current_mode);
}
//----------------------------Extra Functions-----------------------------------//
//This will turn off all the LEDS
void blank(){
for (int i = 0; i < NUM_LEDS;i++){
leds[i] = CRGB(0,0,0);
}
FastLED.show();
}
//This will make a specific LED the colour specified by the CRGB Colour object. If no colour is passed into the function then DEFAULT_COLOUR is set.
void colour(int led = NUM_LEDS, int color = DEFAULT_COLOUR){
current_colour = color;
if (led == NUM_LEDS){
for (int i = 0; i < NUM_LEDS; i++){
colour(i,color);
}
}
else {
leds[led] = color;
}
FastLED.show();
}
/*
This will set the brightness of the strip. If no value is given the default
is sent.
*/
void setBrightness(int value = DEFAULT_BRIGHTNESS){
FastLED.setBrightness(value);
FastLED.show();
}
void studyMode(){
colour(NUM_LEDS,WhiteSmoke);
}
//----------------------------------Fade Functions-----------------------------------//
/* These are the fading functions. These ensure that in any case the
function will fire
*/
void fadeIn(int delayTime = DEFAULT_FADE_TIME){
for (int i = MINIMUM_BRIGHTNESS; i < MAXIMUM_BRIGHTNESS; i++){
setBrightness(i);
delay(DEFAULT_FADE_TIME);
}
}
void fadeOut(int delayTime = DEFAULT_FADE_TIME){
for (int i = MAXIMUM_BRIGHTNESS; i > MINIMUM_BRIGHTNESS; i--){
setBrightness(i);
delay(DEFAULT_FADE_TIME);
}
}
void breathe(int delayTime = DEFAULT_FADE_TIME){
setBrightness(MINIMUM_BRIGHTNESS);
fadeIn(delayTime);
setBrightness(MAXIMUM_BRIGHTNESS);
fadeOut(delayTime);
setBrightness(MINIMUM_BRIGHTNESS);
}
//------------------------------------------------------------------------------//
//----------------------------Solid Functions-----------------------------------//
/*
These are the solid colour functions.
*/
int randomColour(){
randomSeed(micros()*analogRead(A1)*analogRead(A3));
int seed = random8(142) * random16(142);
while (seed > 141){
if (seed < 0){
seed = seed * -1;
}
seed = seed/random(8);
}
if (fullColourArray[seed] == current_colour){
seed = random8(seed);
}
return fullColourArray[seed];
}
//-----------------------------------------------------------------------------------//
//------------------------------------Animations-------------------------------------//
void slideRight(int col = DEFAULT_COLOUR,int slideDelay = DEFAULT_SLIDE_DELAY){
for (int i = 0; i < NUM_LEDS;i++){
colour(i,col);
delay(slideDelay);
}
}
void slideLeft(int col = DEFAULT_COLOUR,int slideDelay = DEFAULT_SLIDE_DELAY){
for (int i = 0; i < NUM_LEDS;i++){
colour(NUM_LEDS - 1 - i,col);
delay(slideDelay);
}
}
void nightRider(int slideDelay = DEFAULT_SLIDE_DELAY){
slideLeft(randomColour(),slideDelay);
slideRight(randomColour(),slideDelay);
}
void eachRandomLed(int delayTime = DEFAULT_SLIDE_DELAY,int color[] = fullColourArray){
if (color[0] == fullColourArray[0]){
for (int i = 0; i < NUM_LEDS; i ++){
colour(i,randomColour());
delay(delayTime);
}
}
else {
for (int i = 0; i < 7;i++){
colour(i,color[i]);
delay(delayTime);
}
}
}
void switchColour(int delayTime = DEFAULT_SWITCH_DELAY,int color = randomColour()){
colour(NUM_LEDS,color);
delay(delayTime);
}
//-----------------------------------------------------------------------------------//
void strobe(int color = current_colour, int delayTime = DEFAULT_SWITCH_DELAY){
colour(color);
delay(delayTime);
colour(Black);
delay(delayTime);
}
//Patterns
//Alternating colours in row from pallet