-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathclock.ino
68 lines (54 loc) · 1.22 KB
/
clock.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
#include "tm1637.h"
#include "ds1302.h"
void setTime(byte hr, byte mi) {
TM1637_display_digit(0, hr / 10);
TM1637_display_digit(1, hr % 10);
TM1637_display_digit(2, mi / 10);
TM1637_display_digit(3, mi % 10);
}
int main(void) {
Time time;
byte isPressed = 0;
byte looper = 0;
/* setup */
pinMode(5, INPUT);
TM1637_init(1/*enable*/, 3/*brightness*/);
DS1302_init();
setTime(88, 88);
TM1637_display_colon(1);
_delay_ms(300);
while(1) {
if (analogRead(0) < 900) { /* Change in range 800..1000 if button doesn't work properly */
isPressed = isPressed == 255 ? 255 : isPressed + 1;
time.mi = time.mi + 1;
if (time.mi >= 60) {
time.mi = 0;
time.hr = time.hr + 1;
if (time.hr >= 24)
time.hr = 0;
}
setTime(time.hr, time.mi);
TM1637_display_colon(0);
if (isPressed < 15)
_delay_ms(100);
else
_delay_ms(10);
continue;
}
if (isPressed) {
isPressed = 0;
DS1302_set(time);
TM1637_display_colon(1);
continue;
}
DS1302_get(&time);
if (time.hr >= 24 || time.mi >= 60) {
time.hr = 0;
time.mi = 0;
}
setTime(time.hr, time.mi);
looper = (looper + 1) % 16;
TM1637_display_colon(looper > 8);
_delay_ms(60);
}
}