99 lines
2.1 KiB
C++
99 lines
2.1 KiB
C++
#include <Adafruit_CircuitPlayground.h>
|
|
#include <Adafruit_Circuit_Playground.h>
|
|
|
|
#define BREAK_TIME 5
|
|
#define WORK_TIME 25
|
|
#define NUM_PIXELS 10
|
|
boolean work = false;
|
|
|
|
void setup() {
|
|
CircuitPlayground.begin();
|
|
}
|
|
|
|
void loop() {
|
|
// Wait for button press to reset/start timer
|
|
int counter = 0;
|
|
while (!CircuitPlayground.leftButton() &&
|
|
!CircuitPlayground.rightButton()) {
|
|
delay(10);
|
|
counter++;
|
|
if (counter % 6000 == 0) {
|
|
alert();
|
|
}
|
|
}
|
|
work = !work;
|
|
int goal = 0;
|
|
if (work) {
|
|
goal = 6000 / NUM_PIXELS * WORK_TIME;
|
|
} else {
|
|
goal = 6000 / NUM_PIXELS * BREAK_TIME;
|
|
}
|
|
// Turn ON all the NeoPixels
|
|
if (work) {
|
|
lights(0, 255, 255, 0);
|
|
} else {
|
|
lights(0, 0, 255, 255);
|
|
}
|
|
|
|
|
|
int t = 0;
|
|
int timer_counter = 0;
|
|
boolean paused = true;
|
|
while (t < 10) {
|
|
if (!paused) {
|
|
delay(10);
|
|
timer_counter++;
|
|
}
|
|
if (CircuitPlayground.leftButton() ||
|
|
CircuitPlayground.rightButton()) {
|
|
paused = !paused;
|
|
if (paused) {
|
|
lights(t, 128, 128, 128);
|
|
} else if (work) {
|
|
lights(t, 255, 255, 0);
|
|
} else if (!work) {
|
|
lights(t, 0, 255, 255);
|
|
}
|
|
|
|
delay(200); //bc otherwise it gets triggered multiple times
|
|
}
|
|
|
|
if (timer_counter == goal) {
|
|
CircuitPlayground.setPixelColor(t, 0, 0, 0);
|
|
timer_counter = 0;
|
|
t++;
|
|
}
|
|
}
|
|
alert();
|
|
|
|
}
|
|
|
|
void lights(int n, int r, int g, int b) {
|
|
for (int p = n; p < NUM_PIXELS; p++) {
|
|
CircuitPlayground.setPixelColor(p, r, g, b);
|
|
}
|
|
}
|
|
|
|
void alert() {
|
|
if (CircuitPlayground.slideSwitch()) {
|
|
lights(0, 255, 0, 0);
|
|
CircuitPlayground.playTone(523, 75);
|
|
CircuitPlayground.playTone(659, 75);
|
|
lights(0, 0, 0, 0);
|
|
CircuitPlayground.playTone(880, 75);
|
|
CircuitPlayground.playTone(262, 75);
|
|
lights(0, 255, 0, 0);
|
|
CircuitPlayground.playTone(330, 75);
|
|
CircuitPlayground.playTone(440, 75);
|
|
lights(0, 0, 0, 0);
|
|
} else {
|
|
lights(0, 255, 0, 0);
|
|
delay(150);
|
|
lights(0, 0, 0, 0);
|
|
delay(150);
|
|
lights(0, 255, 0, 0);
|
|
delay(150);
|
|
lights(0, 0, 0, 0);
|
|
}
|
|
}
|