1
2
3
4
5#define TIME_SELECT_BUTTON 2
6#define START_BUTTON 3
7#define STOP_BUTTON 4
8#define TIME_30_LIGHT 6
9#define TIME_60_LIGHT 7
10#define TIME_90_LIGHT 8
11#define TIME_120_LIGHT 9
12#define ACTIVE_LIGHT 10
13#define ACTIVE_PIN 11
14
15bool timerActive;
16unsigned long timerLength;
17unsigned long startTime;
18unsigned long duration;
19
20
21
22void setup() {
23 pinMode(START_BUTTON, INPUT_PULLUP);
24 pinMode(STOP_BUTTON, INPUT_PULLUP);
25 pinMode(TIME_SELECT_BUTTON, INPUT_PULLUP);
26 pinMode(ACTIVE_LIGHT, OUTPUT);
27 pinMode(ACTIVE_PIN, OUTPUT);
28 pinMode(TIME_30_LIGHT, OUTPUT);
29 pinMode(TIME_60_LIGHT, OUTPUT);
30 pinMode(TIME_90_LIGHT, OUTPUT);
31 pinMode(TIME_120_LIGHT, OUTPUT);
32 digitalWrite(ACTIVE_LIGHT, LOW);
33 digitalWrite(TIME_30_LIGHT, HIGH);
34 digitalWrite(TIME_60_LIGHT, LOW);
35 digitalWrite(TIME_90_LIGHT, LOW);
36 digitalWrite(TIME_120_LIGHT, LOW);
37 digitalWrite(ACTIVE_PIN, LOW);
38
39 timerLength = 30;
40 timerActive = false;
41}
42
43void WaitForStart(){
44
45
46
47
48 while (digitalRead(START_BUTTON) == HIGH){
49
50
51 if (digitalRead(TIME_SELECT_BUTTON) == LOW){
52 switch(timerLength){
53 case 30:
54 timerLength = 60;
55 digitalWrite(TIME_30_LIGHT, LOW);
56 digitalWrite(TIME_60_LIGHT, HIGH);
57 break;
58 case 60:
59 timerLength = 90;
60 digitalWrite(TIME_60_LIGHT, LOW);
61 digitalWrite(TIME_90_LIGHT, HIGH);
62 break;
63 case 90:
64 timerLength = 120;
65 digitalWrite(TIME_90_LIGHT, LOW);
66 digitalWrite(TIME_120_LIGHT, HIGH);
67 break;
68 case 120:
69 timerLength = 30;
70 digitalWrite(TIME_120_LIGHT, LOW);
71 digitalWrite(TIME_30_LIGHT, HIGH);
72 break;
73 }
74
75 delay(500);
76 }
77 }
78
79
80 timerActive = true;
81
82 startTime = millis();
83
84
85
86 duration = timerLength * 60 * 1000;
87
88 digitalWrite(ACTIVE_PIN, HIGH);
89 digitalWrite(ACTIVE_LIGHT, HIGH);
90}
91
92void loop() {
93
94 if (!timerActive){
95 WaitForStart();
96 }
97
98
99 while (timerActive){
100 if ((digitalRead(STOP_BUTTON) == LOW) ||
101 ((millis() - startTime) >= duration)){
102
103
104 timerActive = false;
105 digitalWrite(ACTIVE_PIN, LOW);
106 digitalWrite(ACTIVE_LIGHT, LOW);
107 }
108
109 delay(1000);
110 }
111}