-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtimer
205 lines (164 loc) · 4.84 KB
/
timer
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
//https://create.arduino.cc/projecthub/ozyRonald/alarm-clock-and-timer-working-standalone-b683db?ref=tag&ref_id=timer&offset=3
#include <EEPROM.h>
#include <Pushbutton.h>
#include <EEPROM.h>
#include <RTClib.h>
#include <LCD.h>
#include <LiquidCrystal.h>
#include <LiquidCrystal_I2C.h>
#include <Wire.h>
LiquidCrystal_I2C lcd(0x3F, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
RTC_DS1307 RTC;
const int DS1307 = 0x68;
//const int selectButtonPin = 5; //sets a button to have a selection to the timer management
//const int nextButtonPin = 4;
//const int upButtonPin = 3;
//const int downButtonPin = 2;
//const int alarmButtonPin = alarmSel; //alarmSel is a later function
//const boolean alarmSystem = 7;
//const boolean timerForLED = 8;
enum mainSelection {
ALARM_SWITCH = 1;
ALARM_START,
ALARM_SET,
CLOCK_SET,
ALARM_AUTO,
RUN_CLOCK
};
enum mainSelection key = RUN_CLOCK;
int alarmMinuteStart = 1;
int alarmHourStart = 1;
int alarmMinuteStop = 2;
int alarmHourStop = 2;
int alarmPlus = 0; //Working hours of the lights; Maximum of 6
boolean alarmOnOff = false;
boolean autoManual = false; //Timer being automatic or manual
int alarmOffset = 6;
int yr = 2000;
int mo = 1;
int dy = 1;
int hr = 0;
int mn = 0;
int setYr = 00;
int setMo = 1;
int setDy = 1;
int setHr = 0;
int setMn = 0;
boolean dayLightSaving = false;
boolean aBlink = true;
const int loopCheckMax = 80; //Duration of the loops in the settings
int loopCheck = 0; //To control if there is any interaction
unsigned long clockDisplayCheck = millis();
int lcdDisplayCheck = 0; //Counter for controling the time the lcd will be on
boolean timerLight = false; //Set the relays for the alarm lights
int tiemrLightStage = 0;
Servo servo;
int posit = 0;
void setup() {
// put your setup code here, to run once:
servo.attach(8);
pinMode(lightAlarmPin, OUTPUT);
pinMode(alarmSystemPin, OUTPUT);
pinMOde(timerForLED, OUTPUT);
lcd.begin(16,2);
lcd.print("Snap!");
Wire.begin();
RTC.begin();
Serial.begin(9600);
clockRunning();
lcd.clear();
lcd.on();
displayLcdFirstLine(2);
readTimeNow();
displayTimeNow(2);
readAlarm();
}
void loop() {
lcd.setCursor(0, 1);
lcd.print(millis() / 1000);
/*
// put your main code here, to run repeatedly:
for (posit = 0; posit <= 180; posit += 1) {
servo.write(posit);
delay(15);
}
for(posit = 180; posit >= 0; posit -= 1) {
servo.write(posit);
delay(15);
}
/*
CODE FOR THE TIMER AND CLOCK TO WORK SEPARATELY
This program utilizes a LCD display made by Arduino
*/
key = RUN_CLOCK();
lightMahuallyOnOff();
lcdLight(); //Turns on the lcd light on demand
if ((millis() - clockDisplayCheck) > 500) { //Reading and displaying date and time continuesly every 0.5 seconds
clockRunning();
clockDisplayCheck = millis(); //Sets the timer variable
readTimeNow(); //Reads the time out of the Real Time Clock
displayTimeNow(2); //Displays the current time and the digit to blink
readAlarm(); //Reads the alarm settings out off the EEPROM
displayLcdFirstLine( 0); //Basic display line
alarmActivate(); //Sets the alarm
timerLightOnOff();
}
if (selectButton.getSingleDebouncedPress())
{
lcdDisplayCheck = 0; // lcd back to maximum time
lcdLight(); //Turns the lcd on
mainKeySelection(); // reads keySelection ALARM_ON_OFF,ALARM_SEASON,ALARM_SET,CLOCK_SET,RUN_CLOCK,
// lcd.setCursor(0, 0);
switch (key) {
case ALARM_ON_OFF:
setTimerOnOff();
break;
case ALARM_SEASON:
setTimerPlus();
break;
case ALARM_SET:
setHr = alarmHourStop;
setMn = alarmMinuteStop;
lcd.setCursor(0, 0);
lcd.print("Set alarm time ");
presetClockTime(alarmOffSet); //Gives an off-set to the alarm stopping time of 6? hours
if (setHr == 12) { //to prevent the timer passing mid-night
setHr = 11;
setMn = 59;
}
saveAlarmSet();
// readAlarm();
break;
case CLOCK_SET:
presetClockDate();
readTimeNow(); //reading the current time to display in presetClockTime
setHr = hr;
setMn = mn;
lcd.setCursor(0, 0);
lcd.print("Set clock time ");
presetClockTime(0); //Time can be set starting at zero. The function is also in use to set the alarm stopping time
saveClock();
break;
case AlARM_AUTO:
alarmAutoManual();
break;
}
}
}
void readTimeNow() {
DateTime.now = RTC.now();
yr = now.year();
mo = now.month();
dy = now.day();
hr = now.hour();
mn = now.minunte();
}
void displayTimeNow(int digitBlink) {
char textDT[16];
sprintf(textDT, hr, mn, dy, mo, yr);
lcd.setCursor(0, 1);
lcd.print(textDT);
lcd.setCursor(digitBlink, 1);
}
void
*/