3 // minutes of "dawn" before alarm
5 // minutes of "dawn" + minutes of blue blinding light
8 // number of available alarms
15 #define DS1307_ADDRESS 0x68
17 int st = 0; // alarm status (minutes from alarm - TIN)
18 char alarms[NALARMS][5];
19 char cmin; // current minute
20 int a = -1; // current alarm
26 set_time(11,9,2,5,0,0,0);
32 digitalWrite(RPIN,255);
36 // read alarms from storage
37 for ( int i = 0 ; i < NALARMS ; i ++ ) {
44 // read commands from serial
46 // read time, check alarms
52 // act on status: LEDs and buzzer
57 // wait about till the next second
63 // Set the current time
64 void set_time(int y,int m,int d, int w, int hh, int mm, int ss) {
65 Wire.beginTransmission(DS1307_ADDRESS);
67 Wire.send(bin2bcd(ss));
68 Wire.send(bin2bcd(mm));
69 Wire.send(bin2bcd(hh));
71 Wire.send(bin2bcd(d));
72 Wire.send(bin2bcd(m));
73 Wire.send(bin2bcd(y));
75 Wire.endTransmission();
79 Wire.beginTransmission(DS1307_ADDRESS);
81 Wire.endTransmission();
83 Wire.requestFrom(DS1307_ADDRESS, 6);
85 int mm = bcd2bin(Wire.receive());
86 int hour = bcd2bin(Wire.receive());
87 int wday = Wire.receive();
88 int day = bcd2bin(Wire.receive());
89 int month = bcd2bin(Wire.receive());
92 for ( int i = 0; i < NALARMS ; i ++ ) {
94 if ( ( alarms[i][0] & ( 1 << (wday - 1) ) ) ||
95 (month == alarms[i][1] && day == alarms[i][2]) ) {
97 if ( hour == alarms[i][3] && mm == alarms[i][4]) {
98 // this is alarm hour!
102 if ( ( alarms[i][0] & 128 ) == 0 ) {
103 // this alarm won't be repeated
104 alarms[i] = { 0,0,0,0,0 };
120 if ( st > 0 && st < TIN) {
121 int y = int(float(st*255)/TIN);
125 } else if (st == TIN) {
128 analogWrite(BPIN,255);
129 } else if (st == TOUT) {
133 analogWrite(RPIN,255);
139 // BCD helper functions from adafruit-RTClib
140 static uint8_t bcd2bin (uint8_t val) { return val - 6 * (val >> 4); }
141 static uint8_t bin2bcd (uint8_t val) { return val + 6 * (val / 10); }
143 // vim: set filetype=c: