-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsmartclock.ino
More file actions
288 lines (226 loc) · 6.04 KB
/
smartclock.ino
File metadata and controls
288 lines (226 loc) · 6.04 KB
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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
//We always have to include the library
#include "LedControl.h"
#include <Time.h>
#include "notes.h"
//this has to be changed
#define SSID "Wifi SSID"
#define PASS "WIFI PASSOWRD"
#include <SoftwareSerial.h>
SoftwareSerial ESPserial(2 , 4); // RX | TX of ESP module
#include <Wire.h>
#include <SparkFun_APDS9960.h>
LedControl lc=LedControl(12,13,10,4);
SparkFun_APDS9960 apds = SparkFun_APDS9960();
uint16_t ambient_light = 0;
uint16_t red_light = 0;
uint16_t green_light = 0;
uint16_t blue_light = 0;
byte number_to_led[9] = {B00000000,B00000001,B00000011,B00000111,B00001111,B00011111,B00111111,B01111111,B11111111};
byte number_to_led2[9] = {B11111111,B11111110,B11111100,B11111000,B11110000,B11100000,B11000000,B10000000,B00000000};
int proximity_count = 0;
uint8_t proximity_data = 0;
int reveil_armed = 0; //0 = not armed; 1 = armed; 2 = ringing
int reveil_heure = 00; //hour of alarm
int reveil_minute = 00; //minute of alarm
int reveil_jour = 00; //day of alarm
int time_to_alarm = 0; //time until alarm rings in minutes
int a,b,c,d; //used for animations
int dom_tomorrow = 0; //dom = day of month
int intensity = 10;
void setup()
{
setTime(00,00,00 ,25,01,2015);
pinMode(5, OUTPUT); //R
pinMode(6, OUTPUT); //G
pinMode(9, OUTPUT); //B
pinMode(3, OUTPUT);//buzzer
pinMode(8, OUTPUT); //ESP RESET
//alarm();
//beep beep
tone(3,440);
delay(100);
noTone(3);
delay(100);
tone(3,440);
delay(100);
noTone(3);
#ifdef serial
Serial.begin(9600);
Serial.println("bijour");
#endif
ESP_init();
while(ATcheck() == false)
{
#ifdef serial
Serial.println("ATcheck is wrong ... waiting ...");
#endif
delay(1000);
}
connectWiFi();
apds_init();
matrix_init();
matrix_wifi();
while(isConnected()==false)
{
#ifdef serial
Serial.println("Not connected to AP");
#endif
rgb(random(0,10)*10,random(0,10)*10,random(0,10)*10);
matrix_update();
matrix_luminosity();
delay(100);
matrix_wifi();
delay(2000);
connectWiFi();
delay(3000);
}
delay(500);
while(getSettings()==false)
{
matrix_wifi();
rgb(random(0,10)*10,random(0,10)*10,random(0,10)*10);
if(isConnected()==false)
{
connectWiFi();
}
delay(3000);
}
rgb(0,0,0);
#ifdef serial
Serial.println("entering loop");
#endif
//beep beep
/*tone(3,240);
delay(100);
noTone(3);
delay(100);
tone(3,330);
delay(150);
noTone(3);
delay(100);
tone(3,430);
delay(200);
noTone(3);*/
for(int a = 0;a<20 ;a++)
{
rgb(random(0,10)*10,random(0,10)*10,random(0,10)*10);
tone(3, random(20,400));
delay(50);
}
noTone(3);
//animate(4);
}
void loop()
{
for(int i=0;i<35;i++)
{
//matrix_animate();
if(reveil_armed == 1)
{
//Set color of led
time_to_alarm = calc_time_to_alarm();
//Serial.print("tta");
//Serial.println(time_to_alarm);
if(time_to_alarm > 0)
{
if(time_to_alarm >= 8*60)
{
rgb_fade(505, intensity); //code 505
}
else
{
rgb_fade(time_to_alarm,intensity);
}
if(apds.readProximity(proximity_data))
{
//Serial.print("proximity : ");
//Serial.println(proximity_data);
if(proximity_data > 200)
{
//if proximity sensor is on then show time of alarm
//reveil_heure // reveil_minute
show_chiffre(3,reveil_heure/10);
show_chiffre(2,reveil_heure%10);
show_chiffre(1,reveil_minute/10);
show_chiffre(0,reveil_minute%10);
}
else
{
matrix_update();
matrix_luminosity();
}
}
}
else
{
matrix_update();
matrix_luminosity();
}
if(reveil_jour == day() && (reveil_heure*60 + reveil_minute) <= (hour()*60 + minute()) )
{
reveil_armed = 2;
matrix_update();
matrix_luminosity();
}
}
else if(reveil_armed == 2)
{
//alarm !
rgb(255,255,255);
matrix_update();
matrix_luminosity();
//Serial.println("ALARME !");
/*watch_stop_alarm();
if(reveil_armed == 2) //to avoid double beep
{
tone(3, 440);
delay(50);
noTone(3);
delay(50);
tone(3, 440);
delay(50);
noTone(3);
delay(50);
watch_stop_alarm();
}
if(reveil_armed == 2) //to avoid double beep
{
tone(3, 440);
delay(500);
noTone(3);
watch_stop_alarm();
}*/
alarm_happy();
// getSettings();
}
else
{
rgb(0,0,0); //black LED
matrix_update();
matrix_luminosity();
}
}
#ifdef serial
Serial.println("routine");
#endif
//ATcheck();
if(isConnected()==true)
{
getSettings();
#ifdef serial
Serial.println("is connected loop");
#endif
//matrix_wifi();
}
else
{
#ifdef serial
Serial.println("Not connected");
#endif
matrix_wifi();
delay(100);
matrix_update();
connectWiFi();
delay(1500);
}
}