-
Notifications
You must be signed in to change notification settings - Fork 0
/
Project_-_Pomodoro_Timer.ino
287 lines (245 loc) · 5.84 KB
/
Project_-_Pomodoro_Timer.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
/*============================================================================
Adafruit Pomodoro Timer
A 60min timer that decrement by minute simply by changing colors.
Displays a countdown timer on the NeoPixels and sounds an alarm.
How it Works:
The time to countdown is specified by 6000 milliseconds (total_time).
That's approximately 1 minute. And at each minute decrement, a Neopixel
light changes color, or simply turn itself off depending on how the timer
was set.
Example: If timer was set to 40 minutes, the color pink would
fill all the neopixel lights available. When 2 minutes have passed
from 40 minutes (ie. 38 minutes left on the clock) two of the
pink neopixel light would change from their initial color to
yellow, the next Neopixel color that represents the next 10 minute interval
of 30 minutes.
NeoPixel Colors:
* Purple Rain : 60 mins left
* Ruby Red: 50 mins left
* Hot Pink: 40 mins left
* Sun Gold: 30 mins left
* Green Jade: 20 mins left
* Light Blue: 10 mins left
Code Challenges:
* Add music at the end of timer (check, though not via C#)
* Change orb color by user preference via C# code
=============================================================================*/
#include <Adafruit_CircuitPlayground.h>
#include "pitches.h"
#include <Wire.h>
#include <SPI.h>
#define NUM 7
#define DIAMOND 0xB9F2FF
#define BLUE 0x008080 // 10 to 20 mins
#define GREEN 0x33FF33 // 20 to 30 mins
#define GOLD 0xFFD700 // 30 to 40 mins
#define PINK 0xFF2F2F // 40 to 50 mins
#define RED 0xFF0101 // 50 to 60 mins
#define PURPLE 0x4B0082 // 60 to 70 mins
//from adafruit_circuitplayground.express import cpx
int melody[] = {
NOTE_E7, NOTE_E7, 0, NOTE_E7,
0, NOTE_C7, NOTE_E7, 0,
NOTE_G7, 0, 0, 0,
NOTE_G6, 0, 0, 0
};
int numNotes;
int noteDurations[] = { // note durations
12, 12, 12, 12,
12, 12, 12, 12,
12, 12, 12, 12,
12, 12, 12, 12,
12, 12, 12, 12,
12, 12, 12, 12,
12, 12, 12, 12,
12, 12, 12, 12,
9, 9, 9,
12, 12, 12, 12,
12, 12, 12, 12,
12, 12, 12, 12,
12, 12, 12, 12,
12, 12, 12, 12,
12, 12, 12, 12,
12, 12, 12, 12,
9, 9, 9,
12, 12, 12, 12,
12, 12, 12, 12,
12, 12, 12, 12,
};
float total_time = 60000; // approx 1 min per pixel light
float delta_time = total_time / 500; // use for debugging purposes
bool slideSwitch = CircuitPlayground.slideSwitch();
uint8_t r, g, b;
uint8_t currentColor = r + g + b;
uint32_t colors[] = { DIAMOND, BLUE, GREEN, GOLD, PINK, RED, PURPLE };
bool is4Pressed = false;
bool is19Pressed = false;
void setup()
{
CircuitPlayground.begin();
Serial.begin(115200);
pinMode(21, INPUT);
CircuitPlayground.setBrightness(125);
currentColor = 0;
numNotes = sizeof(melody)/sizeof(int);
}
void superMarioTone()
{
for (int thisNote = 0; thisNote < numNotes; thisNote++)
{
int noteDuration = 800 / noteDurations[thisNote];
CircuitPlayground.playTone(melody[thisNote], noteDuration);
int pauseBetweenNotes = noteDuration * 1.30;
delay(pauseBetweenNotes);
}
}
void timer()
{
//int myNum = NUM - 1;
if(CircuitPlayground.slideSwitch() == true)
{
//cpx.play_file("Wild_Eep.wav")
while(currentColor > 1)
{
currentColor = currentColor - 1;
for (int p=0; p<10; p=p+1)
{
delay(total_time);
CircuitPlayground.setPixelColor(p, colors[currentColor]); // 50 to 60 mins
}
}
for (int p=0; p<10; p=p+1)
{
delay(total_time);
CircuitPlayground.setPixelColor(p, 0, 0, 0); // 0 to 10 mins
}
while (true) {
superMarioTone();
//CircuitPlayground.playTone(800, 250);
delay(250);
superMarioTone();
//CircuitPlayground.playTone(1500, 250);
delay(250);
superMarioTone();
//CircuitPlayground.playTone(1000, 250);
delay(250);
}
}
else
{
// do nothing
}
}
void rightButton()
{
if(!is19Pressed)
{
if(digitalRead(19) == HIGH)
{
is19Pressed = true;
if(currentColor != NUM - 1)
{
currentColor++;
}
else
{
CircuitPlayground.playTone(800, 250);
currentColor = NUM - 1;
}
}
}
else
{
if(digitalRead(19) == LOW)
{
is19Pressed = false;
}
}
}
void leftButton()
{
if(!is4Pressed)
{
if(digitalRead(4) == HIGH)
{
is4Pressed = true;
if (currentColor == 0)
{
CircuitPlayground.playTone(400, 250);
CircuitPlayground.playTone(400, 250);
currentColor = 0;
}
else if (currentColor == 1)
{
CircuitPlayground.playTone(800, 250);
currentColor = 1;
}
else
{
currentColor--;
}
}
}
else
{
if(digitalRead(4) == LOW)
{
is4Pressed = false;
}
}
}
void slideSwitcher()
{
if(slideSwitch == true)
{
if(digitalRead(21) == HIGH)
{
slideSwitch = true;
Serial.println("slider");
}
else
{
if(digitalRead(21) == LOW)
{
slideSwitch = false;
}
}
}
}
void loop()
{
if(Serial.available())
{
uint8_t id = Serial.read();
if(id == 0xAA)
{
byte buf[5];
uint32_t colorvalue = 0;
// uint8_t pin = Serial.read();
// r = Serial.read();
// g = Serial.read();
// b = Serial.read();
// for (int pin=0; pin<10; pin=pin+1)
// {
// CircuitPlayground.setPixelColor(pin, r, g, b);
// }
buf[0] = Serial.read();
buf[1] = Serial.read();
buf[2] = Serial.read();
buf[3] = Serial.read();
buf[4] = Serial.read();
colorvalue = *((uint32_t*)&buf[1]);
colors[buf[0]] = colorvalue;
}
}
else
{
for (int p=0; p<10; p=p+1)
{
CircuitPlayground.setPixelColor(p, colors[currentColor]);
}
}
leftButton();
rightButton();
timer();
}