-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpomodoro.ino
105 lines (84 loc) · 2.18 KB
/
pomodoro.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
#include <Adafruit_NeoPixel.h>
#define NUM_PIXELS 12 // amount of LED
unsigned long interval = 60000; // the time we need to wait
unsigned long previousMillis = 0;
unsigned long pause = 500;
uint32_t currentColor;// current Color in case we need it
uint32_t red;
uint16_t currentPixel = 0;// what pixel are we operating on
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_PIXELS, 2, NEO_GRB + NEO_KHZ800);
int ledButton = 7;
int startButton = 5;
int buttonState = LOW;
int reading;
int previous = HIGH;
long time = 0;
long debounce = 500;
void setup() {
pinMode(startButton, INPUT_PULLUP);
pinMode(ledButton, OUTPUT);
currentColor = strip.Color(0,255,0);
currentPixel = 0;
strip.begin();
strip.setBrightness(15);
strip.show(); // Initialize all pixels to 'off'
}
void loop(){
reading = digitalRead(startButton);
if (reading == HIGH && previous == LOW && (millis() - time) > debounce) {
if (buttonState == HIGH) {
buttonState = LOW;
} else if (buttonState == LOW) {
buttonState = HIGH;
}
time = millis();
}
previous = reading;
if (buttonState == HIGH) {
digitalWrite(ledButton, HIGH);
pomodoro();
timesUp();
buttonState = LOW;
}
else if (buttonState == LOW) {
digitalWrite(ledButton, LOW);
}
}
void pomodoro(){
unsigned long currentMillis = millis(); // grab current time
for (uint16_t led = 0; led < strip.numPixels(); led++) {
strip.setPixelColor(currentPixel,currentColor);
strip.show();
while (millis() < currentMillis + interval) {
// wait
}
currentPixel++;
currentMillis = millis();
}
currentPixel = 0;
}
void timesUp() {
for (int t = 0; t<4; t++) {
for(uint16_t i=0; i<strip.numPixels(); i++) {
strip.setPixelColor(i,0,0,0);
strip.show();
}
wait();
for(uint16_t i=0; i<strip.numPixels(); i++) {
strip.setPixelColor(i,currentColor);
strip.show();
}
wait();
}
for(uint16_t i=0; i<strip.numPixels(); i++) {
strip.setPixelColor(i,0,0,0);
strip.show();
}
}
void wait() {
unsigned long currentMillis = millis(); // grab current time
while (millis() < currentMillis + pause) {
// wait
}
currentMillis = millis();
}