-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patharduino.ino
343 lines (302 loc) · 8.79 KB
/
arduino.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
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
#include <FastLED.h>
#include <LiquidCrystal.h>
#define LED_PIN 6
#define steamerPin 10
#define NUM_LEDS 60
#define BRIGHTNESS 255
#define LED_TYPE WS2811
#define COLOR_ORDER GRB
CRGB leds[NUM_LEDS];
#define startButton 13
#define emergencyButton 8
#define UPDATES_PER_SECOND 60
#define JoyStick_X A1
CRGBPalette16 currentPalette;
TBlendType currentBlending;
extern CRGBPalette16 myRedWhiteBluePalette;
extern const TProgmemPalette16 myRedWhiteBluePalette_p PROGMEM;
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
#define pwmPin 9
int i, x, y, tmp;
long time, cd, digit;
bool left, right, start;
void setup() {
delay( 1000 ); // power-up safety delay
FastLED.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
FastLED.setBrightness( BRIGHTNESS );
currentPalette = RainbowColors_p;
currentBlending = LINEARBLEND;
for (i=0; i<60; i++) {
leds[i] = CRGB::Green;
}
FastLED.show();
pinMode(steamerPin, OUTPUT);
pinMode(startButton, INPUT);
pinMode(emergencyButton, INPUT);
pinMode (JoyStick_X, INPUT);
pinMode(pwmPin, OUTPUT);
analogWrite(pwmPin, 120);
lcd.begin(16, 2);
lcd.setCursor(0,0);
lcd.print("Setting time...");
cd = 180;
start = false;
}
void loop()
{
x = analogRead (JoyStick_X);
if ( x > 650 ) {
lcd.setCursor(0,1);
lcd.print(" ");
lcd.setCursor(0,1);
lcd.print(" -10s");
while ( analogRead(JoyStick_X) > 650 ) {
delay(20);
}
cd = cd - 10;
if (cd < 10) cd = 10;
lcd.setCursor(0,1);
lcd.print(" ");
}
if ( x < 200) {
lcd.setCursor(0,1);
lcd.print(" ");
lcd.setCursor(0,1);
lcd.print(" +10s");
while ( analogRead(JoyStick_X) < 200 ) {
delay(20);
}
cd = cd + 10;
if (cd > 999) cd = 999;
lcd.setCursor(0,1);
lcd.print(" ");
}
if (digitalRead(startButton)) {
start = true;
for (i=0; i<60; i++) {
leds[i] = CRGB::Yellow;
}
FastLED.show();
lcd.setCursor(0,0);
lcd.print("Starting in 3s");
FastLED.setBrightness( 10 );
FastLED.show();
delay(1000);
FastLED.setBrightness( 20 );
FastLED.show();
lcd.setCursor(0,0);
lcd.print("Starting in 2s");
delay(1000);
lcd.setCursor(0,0);
lcd.print("Starting in 1s");
FastLED.setBrightness( BRIGHTNESS );
FastLED.show();
digitalWrite(steamerPin,HIGH);
delay(1000);
digitalWrite(steamerPin,LOW);
lcd.setCursor(0,0);
lcd.print(" ");
lcd.setCursor(0,0);
lcd.print("Time remaining:");
cd = cd*1000+millis();
}
while (start == true) {
tmp = (cd - millis())/1000 + 1;
if (tmp == 99) {
lcd.setCursor(0,1);
lcd.print(" ");
}
if (tmp == 9) {
lcd.setCursor(0,1);
lcd.print(" ");
}
lcd.setCursor(0,1);
lcd.print(tmp);
lcd.print(" s");
for (i=0; i<60; i++) {
leds[i] = CRGB::Red;
}
FastLED.show();
if (digitalRead(emergencyButton)) {
for (i=0; i<60; i++) {
leds[i] = CRGB::Yellow;
}
FastLED.show();
lcd.setCursor(0,0);
lcd.print(" ");
lcd.setCursor(0,0);
lcd.print("EMERGENCY STOP");
lcd.setCursor(0,1);
lcd.print(" ");
time = millis();
digitalWrite(steamerPin,HIGH);
delay(1000);
digitalWrite(steamerPin,LOW);
while (millis() - time < 20000) {
if (digitalRead(startButton)) {
delay(50);
if (digitalRead(startButton)) delay(50); break;
}
}
start = false;
lcd.setCursor(0,0);
lcd.print(" ");
lcd.setCursor(0,0);
lcd.print("SETTING TIME...");
lcd.setCursor(0,1);
lcd.print(" ");
cd = 180;
for (i=0; i<60; i++) {
leds[i] = CRGB::Green;
}
delay(100);
}
if (tmp <= 0 ) {
lcd.setCursor(0,0);
lcd.print(" ");
lcd.setCursor(0,0);
lcd.print("IRONING COMPLETE");
lcd.setCursor(0,1);
lcd.print(" ");
lcd.setCursor(0,1);
lcd.print("PLEASE WAIT.");
digitalWrite(steamerPin,HIGH);
delay(1000);
digitalWrite(steamerPin,LOW);
start = false;
time = millis();
while (true) {
ChangePalettePeriodically();
static uint8_t startIndex = 0;
startIndex = startIndex + 1; /* motion speed */
FillLEDsFromPaletteColors( startIndex);
FastLED.show();
FastLED.delay(1000 / UPDATES_PER_SECOND);
if (millis() > time + 30000) break;
}
lcd.setCursor(0,0);
lcd.print(" ");
lcd.setCursor(0,0);
lcd.print("SETTING TIME...");
lcd.setCursor(0,1);
lcd.print(" ");
cd = 180;
for (i=0; i<60; i++) {
leds[i] = CRGB::Green;
}
}
}
if (cd < 100 && digit == 3) {
lcd.setCursor(0,1);
lcd.print(" ");
digit = 2;
}
if (cd >= 100) digit = 3;
lcd.setCursor(0,1);
lcd.print(cd);
FastLED.show();
}
void FillLEDsFromPaletteColors( uint8_t colorIndex)
{
uint8_t brightness = 255;
for( int i = 0; i < NUM_LEDS; i++) {
leds[i] = ColorFromPalette( currentPalette, colorIndex, brightness, currentBlending);
colorIndex += 3;
}
}
void ChangePalettePeriodically()
{
uint8_t secondHand = (millis() / 1000) % 60;
static uint8_t lastSecond = 99;
if( lastSecond != secondHand) {
lastSecond = secondHand;
if( secondHand == 0) {
currentPalette = RainbowColors_p;
currentBlending = LINEARBLEND;
}
if( secondHand == 10) {
currentPalette = RainbowStripeColors_p;
currentBlending = NOBLEND;
}
if( secondHand == 15) {
currentPalette = RainbowStripeColors_p;
currentBlending = LINEARBLEND;
}
if( secondHand == 20) {
SetupPurpleAndGreenPalette();
currentBlending = LINEARBLEND;
}
if( secondHand == 25) {
SetupTotallyRandomPalette();
currentBlending = LINEARBLEND;
}
if( secondHand == 30) {
SetupBlackAndWhiteStripedPalette();
currentBlending = NOBLEND;
}
if( secondHand == 35) {
SetupBlackAndWhiteStripedPalette();
currentBlending = LINEARBLEND;
}
if( secondHand == 40) {
currentPalette = CloudColors_p;
currentBlending = LINEARBLEND;
}
if( secondHand == 45) {
currentPalette = PartyColors_p;
currentBlending = LINEARBLEND;
}
if( secondHand == 50) {
currentPalette = myRedWhiteBluePalette_p;
currentBlending = NOBLEND;
}
if( secondHand == 55) {
currentPalette = myRedWhiteBluePalette_p;
currentBlending = LINEARBLEND;
}
}
}
void SetupTotallyRandomPalette()
{
for( int i = 0; i < 16; i++) {
currentPalette[i] = CHSV( random8(), 255, random8());
}
}
void SetupBlackAndWhiteStripedPalette()
{
fill_solid( currentPalette, 16, CRGB::Black);
currentPalette[0] = CRGB::White;
currentPalette[4] = CRGB::White;
currentPalette[8] = CRGB::White;
currentPalette[12] = CRGB::White;
}
void SetupPurpleAndGreenPalette()
{
CRGB purple = CHSV( HUE_PURPLE, 255, 255);
CRGB green = CHSV( HUE_GREEN, 255, 255);
CRGB black = CRGB::Black;
currentPalette = CRGBPalette16(
green, green, black, black,
purple, purple, black, black,
green, green, black, black,
purple, purple, black, black );
}
const TProgmemPalette16 myRedWhiteBluePalette_p PROGMEM =
{
CRGB::Red,
CRGB::Gray,
CRGB::Blue,
CRGB::Black,
CRGB::Red,
CRGB::Gray,
CRGB::Blue,
CRGB::Black,
CRGB::Red,
CRGB::Red,
CRGB::Gray,
CRGB::Gray,
CRGB::Blue,
CRGB::Blue,
CRGB::Black,
CRGB::Black
};