-
Notifications
You must be signed in to change notification settings - Fork 2
/
UserIO.ino
302 lines (260 loc) · 7.39 KB
/
UserIO.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
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
void setupMode()
{
inSetup = !inSetup;
if (inSetup) {
// Update status LED color
setStatusSetup();
// Set the current display pattern to the test pattern (a pattern which shows the two team colors)
noSignalPatternDisplay = TESTPATTERN;
}
else {
// Exit set-up
// User exited setup
COLOR1 = EEPROM.read(COLOR1_EE);
COLOR2 = EEPROM.read(COLOR2_EE);
stripLength = EEPROM.read(LED_EE);
noSignalPatternDisplay = EEPROM.read(PATTERN_EE);
fill_solid( leds, NUM_LEDS, CRGB::Black );
SetupCustomPalette(colorList[COLOR1], colorList[COLOR2]);
// Update Status LED Color
setStatusRun();
//resume normal operation
}
}
void readUserInputs()
{
//read Pot value and translate to colors/strip length
uint8_t newLength = constrain(map(analogRead(LENGTH_PIN), 0, 1024, 1, 241), 0, 240);
if ((stripLength > newLength) && (addressableStrip == true)){
//need loop to only update pixels to black that are > then new length
//for stripLength to lengthHistory[0]
for( int i = NUM_LEDS-1; i >= newLength; i--) {
leds[i] = CRGB::Black;
}
FastLED.show();
}
stripLength = newLength;
COLOR1 = map(analogRead(COLOR1_PIN), 0, 1024, 0, (ARRAY_SIZE(colorList)));
COLOR2 = map(analogRead(COLOR2_PIN), 0, 1024, 0, (ARRAY_SIZE(colorList)));
SetupCustomPalette(colorList[COLOR1], colorList[COLOR2]);
}
void buttonHandler()
{
// If both buttons are pressed increment the both buttons pressed counter
if((digitalRead(MODE_PIN) == LOW) && (digitalRead(SS_PIN) == LOW)) {
programButtonHoldCount++;
}
// Strip Select Button Logic
if(digitalRead(SS_PIN) == LOW) {
ssButtonHoldCount++;
if ((digitalRead(MODE_PIN) == HIGH) && (programButtonHoldCount == 0) && (inSetup == false)) {
if (ssButtonHoldCount > 40) {
ssButtonHoldCount = 0;
toggleStripSelect();
stripTransistion = true;
}
}
}
else {
// SS_PIN == HIGH
if ((ssButtonHoldCount > 4) && (programButtonHoldCount == 0) ) {
if ((noSignal == true)) {
if (stripTransistion == true) {
stripTransistion = false;
}
else {
//increment output pattern
if ( noSignalPatternDisplay >= 99)
noSignalPatternDisplay = 99;
else
noSignalPatternDisplay = constrain(noSignalPatternDisplay+1, 0, 99);
}
}
ssButtonHoldCount = 0;
}
}
// Mode Button Logic
if(digitalRead(MODE_PIN) == LOW) {
modeButtonHoldCount++;
if ((digitalRead(SS_PIN) == HIGH) && (programButtonHoldCount == 0)) {
if (modeButtonHoldCount > 130) {
modeButtonHoldCount = 0;
setupMode();
setupTransistion = true;
}
}
}
else {
// MODE_PIN == HIGH
if ((modeButtonHoldCount > 4) && (programButtonHoldCount == 0) ) {
if ((noSignal == true)) {
if (setupTransistion == true) {
setupTransistion = false;
}
else {
//increment output pattern
if ( noSignalPatternDisplay == 0)
noSignalPatternDisplay = 0;
else
noSignalPatternDisplay = constrain(noSignalPatternDisplay-1, 0, 99);
}
}
modeButtonHoldCount = 0;
}
}
// Both Buttons Pressed Logic
if ((programButtonHoldCount > 110) && (inSetup == true)) {
//setStatusEEPROM();
setStatusError();
//write EEPROM
saveDefaults();
setupMode();
ssButtonHoldCount = 0;
modeButtonHoldCount = 0;
}
// Reset all the counters if neither button is pressed
if(digitalRead(MODE_PIN) == HIGH && digitalRead(SS_PIN) == HIGH) {
programButtonHoldCount = 0;
ssButtonHoldCount = 0;
modeButtonHoldCount = 0;
}
}
//void SetupCustomPalette(uint8_t HUE_color1, uint8_t HUE_color2)
void SetupCustomPalette(CRGB color1, CRGB color2)
{
teamPalette = CRGBPalette16(
color2, color1, color1, color1,
color1, color1, color1, color1,
color1, color2, color2, color2,
color2, color1, color1, color2 );
}
void testPattern()
{
if (addressableStrip == true) {
uint8_t colorIndex = 1;
for( int i = 0; i < stripLength; i++) {
leds[i] = ColorFromPalette( teamPalette, colorIndex, brightness, NOBLEND);
colorIndex += 3;
}
}
else {
displaySolid( ColorFromPalette(teamPalette, gHue ));
// Long blink Primary and short Blink Secondary, then crossfade, repeat?
// gHue = gHue + 1;
// // Use FastLED automatic HSV->RGB conversion
// showAnalogRGB( CHSV( gHue, 255, 255) );
// delay(5);
}
}
void saveDefaults()
{
//EEPROM write takes 3.3ms
if(writeEEPROM) {
EEPROM.update(SS_EE, addressableStrip);
EEPROM.update(COLOR1_EE, COLOR1);
EEPROM.update(COLOR2_EE, COLOR2);
EEPROM.update(LED_EE, stripLength);
if (noSignalPatternDisplay != TESTPATTERN)
EEPROM.update(PATTERN_EE, noSignalPatternDisplay);
}
}
void initEEPROM()
{
if((digitalRead(MODE_PIN) == LOW) && (digitalRead(SS_PIN) == LOW)) {
//EEPROM write takes 3.3ms
if(writeEEPROM) {
EEPROM.write(SS_EE, addressableStrip);
EEPROM.write(COLOR1_EE, COLOR1);
EEPROM.write(COLOR2_EE, COLOR2);
EEPROM.write(LED_EE, stripLength);
EEPROM.write(PATTERN_EE, noSignalPatternDisplay);
}
}
else {
// Check if defaults have been stored in EEPROM
if (EEPROM.read(COLOR1_EE) == 0xFF) {
//defaults have not been saved, load variables into them
//EEPROM write takes 3.3ms
if(writeEEPROM) {
EEPROM.write(SS_EE, addressableStrip);
EEPROM.write(COLOR1_EE, COLOR1);
EEPROM.write(COLOR2_EE, COLOR2);
EEPROM.write(LED_EE, stripLength);
EEPROM.write(PATTERN_EE, noSignalPatternDisplay);
}
}
else {
//reload from saved values
addressableStrip = EEPROM.read(SS_EE);
COLOR1 = EEPROM.read(COLOR1_EE);
COLOR2 = EEPROM.read(COLOR2_EE);
stripLength = EEPROM.read(LED_EE);
noSignalPatternDisplay = EEPROM.read(PATTERN_EE);
}
}
}
void setStatusCommand() {
// "Purple"
digitalWrite(sREDPIN, LOW);
digitalWrite(sGREENPIN, HIGH);
digitalWrite(sBLUEPIN, LOW);
}
void setStatusSetup() {
// "Yellow"
digitalWrite(sREDPIN, LOW);
digitalWrite(sGREENPIN, LOW);
digitalWrite(sBLUEPIN, HIGH);
}
void setStatusRun() {
// "Blue"
digitalWrite(sREDPIN, HIGH);
digitalWrite(sGREENPIN, HIGH);
digitalWrite(sBLUEPIN, LOW);
}
void setStatusMode() {
if (inSetup == false) {
setStatusRun();
} // "Blue"
else {
setStatusSetup();
} // "Yellow"
}
void setStatusNoSignal()
{
// "Blink Output"
if (inSetup == false) {
digitalWrite(sGREENPIN, HIGH);
digitalWrite(sREDPIN, HIGH);
if (digitalRead(sBLUEPIN) == HIGH) {
digitalWrite(sBLUEPIN, LOW);
}
else {
digitalWrite(sBLUEPIN, HIGH);
}
}
else {
digitalWrite(sBLUEPIN, HIGH);
if (digitalRead(sGREENPIN) == HIGH) {
digitalWrite(sGREENPIN, LOW);
digitalWrite(sREDPIN, LOW);
}
else {
digitalWrite(sGREENPIN, HIGH);
digitalWrite(sREDPIN, HIGH);
}
}
}
void setStatusError()
{
// "Red"
digitalWrite(sREDPIN, LOW);
digitalWrite(sGREENPIN, HIGH);
digitalWrite(sBLUEPIN, HIGH);
}
void setStatusEEPROM()
{
// "cyan"
digitalWrite(sREDPIN, HIGH);
digitalWrite(sGREENPIN, LOW);
digitalWrite(sBLUEPIN, LOW);
}