-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPomodoro.ino
92 lines (76 loc) · 1.78 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
#include <LiquidCrystal.h>
#include <Time.h>
#include <Timer.h>
#define POMODORO_TIME 2700000 // 45 minutos of work...
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
Timer t;
int state = 0, timer = -1;
int secs = 0;
int stopButtonPin = 5;
int resetButtonPin = 4;
void setup() {
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print("Time to Work...");
Serial.begin(9600);
pinMode(stopButtonPin, INPUT);
pinMode(resetButtonPin, INPUT);
int timer = t.every( 1000, syncTime );
state = 1;
}
void syncTime( ) {
secs++;
setTime(secs);
if( secs == POMODORO_TIME / 1000 )
pomodoroIsUp();
digitalClockDisplay();
}
void togglePomodoro( ) {
if( state == 1 ) {
state = 0;
lcd.setCursor(0,0);
lcd.print("STOPPED!!! ");
} else if( state == 0 ) {
lcd.setCursor(0,0);
lcd.print("Time to Work...");
state = 1;
}
}
void pomodoroIsUp( ) {
lcd.setCursor(0,0);
lcd.print("POMODORO!!! ");
tone( 13, 445 );
}
void resetPomodoro( ) {
noTone( 13 );
secs = 0;
lcd.setCursor(0,0);
lcd.print("Time to Work...");
}
void loop() {
int stopButtonState = digitalRead(stopButtonPin);
if (stopButtonState == HIGH) {
togglePomodoro();
}
int resetButtonState = digitalRead(resetButtonPin);
if( resetButtonState == HIGH ) {
resetPomodoro();
}
if( state == 1 )
t.update();
}
void digitalClockDisplay() {
lcd.setCursor(0,1);
lcd.print(hour());
printDigits(minute());
printDigits(second());
}
void printDigits(int digits){
// utility function for digital clock display: prints preceding colon and leading 0
lcd.print(":");
if(digits < 10)
lcd.print('0');
lcd.print(digits);
}