-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild_light.ino
195 lines (164 loc) · 3.72 KB
/
build_light.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
/*
build_light
Copyright (C) 2019 Joseph Auman ([email protected])
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "light.hpp"
//Enable a simple test with the interface.
//#define HARDWARE_TEST
//The buzzer on my unit proved too difficult to control without a relay, so its disabled.
//#define USE_BUZZER
//the lights we have available
typedef enum
{
RED = 0,
YELLOW,
GREEN,
#ifdef USE_BUZZER
BUZZER,
#endif
NUM_LIGHTS
} BUILD_INDICATORS;
//light objects will have the blink logic
light * indicators[NUM_LIGHTS];
//the global blink mode
BLINK_MODE mode = NONE;
void setup()
{
//setup lights (set their pin connections)
indicators[RED] = new light(6);
indicators[YELLOW] = new light(5);
indicators[GREEN] = new light(4);
#ifdef USE_BUZZER
indicators[BUZZER] = new light(3); //connecting it here in case in the future I want to PWM it
#endif
#ifdef HARDWARE_TEST
for(;;)
{
indicators[GREEN]->Off();
indicators[RED]->On(NONE);
delay(1000);
indicators[RED]->Off();
indicators[YELLOW]->On(NONE);
delay(1000);
indicators[YELLOW]->Off();
indicators[GREEN]->On(NONE);
delay(1000);
}
#endif
Serial.begin(115200);
}
void loop()
{
char command = 0;
//process something from the user
if (Serial.available() > 0)
{
//read one command at a time
command = Serial.read();
//echo back what we have if we care
//Serial.write(command);
switch (command)
{
case 'R':
{
//turn the light on with the commanded mode
indicators[RED]->On(mode);
break;
}
case 'r':
{
indicators[RED]->Off();
break;
}
case 'Y':
{
indicators[YELLOW]->On(mode);
break;
}
case 'y':
{
indicators[YELLOW]->Off();
break;
}
case 'G':
{
indicators[GREEN]->On(mode);
break;
}
case 'g':
{
indicators[GREEN]->Off();
break;
}
#ifdef USE_BUZZER
case 'B':
{
indicators[BUZZER]->On(mode);
break;
}
case 'b':
{
indicators[BUZZER]->Off();
break;
}
#endif
case 'A':
{
//turn on all lights with their mode
for (int i = 0; i < NUM_LIGHTS; i++)
{
indicators[i]->On(mode);
}
break;
}
case 'a':
{
for (int i = 0; i < NUM_LIGHTS; i++)
{
indicators[i]->Off();
}
break;
}
case 'f':
{
//set the mode to fast for future On() commands
mode = FAST;
break;
}
case 'm':
{
mode = MEDIUM;
break;
}
case 's':
{
mode = SLOW;
break;
}
case 'n':
{
mode = NONE;
break;
}
default:
{
break;
}
}
}
//call all the lights to blink
for (int i = 0; i < NUM_LIGHTS; i++)
{
indicators[i]->Blink();
}
}