-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclock.ino
75 lines (62 loc) · 1.86 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
69
70
71
72
73
74
75
#define DISP_LATCH 4 // The 3 pins that control the display
#define DISP_CLK 7
#define DISP_DATA 8
#define BUZZER 3 // The speaker enable
const byte numMap[] = {0x40, 0x79, 0x24, 0x30, 0x19, 0x12, 0x02, 0x78, 0X00, 0X10}; // Covert number to segment bits required
const byte digitMap[] = {0xF1, 0xF2, 0xF4, 0xF8}; // Convert digit number to shift bits
int count =2202;
long timer;
void dispNum(int digitNum, int Value) {
digitalWrite(DISP_LATCH, LOW);
if (digitNum == 0 || digitNum==2 || digitNum==3) {
shiftOut(DISP_DATA, DISP_CLK, MSBFIRST, numMap[Value] |0x80);
// Turn on the dot for the second display
shiftOut(DISP_DATA, DISP_CLK, MSBFIRST, digitMap[digitNum]);
} else {
shiftOut(DISP_DATA, DISP_CLK, MSBFIRST, numMap[Value]);
shiftOut(DISP_DATA, DISP_CLK, MSBFIRST, digitMap[digitNum]);
}
digitalWrite(DISP_LATCH, HIGH);
}
void setup() {
pinMode(DISP_LATCH , OUTPUT);
pinMode(DISP_CLK , OUTPUT);
pinMode(DISP_DATA , OUTPUT);
pinMode(BUZZER, OUTPUT);
digitalWrite(BUZZER,HIGH);
timer = millis() +30* 1000;
}
void loop() {
// Separate out the individual digits
int dig1 = count / 1000;
int dig2 = (count - (1000 * dig1)) / 100;
int dig3 = ( (count - (1000 * dig1))- (100 *(dig2))) /10;
int dig4 = count%10;
// Display the digits
dispNum(0 , dig1);
dispNum(1 , dig2);
dispNum(2 , dig3);
dispNum(3 , dig4);
// Check to see if 1 second has passed. If so, set the timer to a second later and increment the count.
if (2*timer < millis()) {
if(count%100<60){
count += 1;
timer = timer + 30*1000;}
else{
count=count+40;
timer = timer + 30*1000;
}
}
if(count>2359){
digitalWrite(BUZZER,LOW);
delay(5000);
digitalWrite(BUZZER,HIGH);
count=0;
}
/*if(count>5959){
digitalWrite(BUZZER,LOW);
delay(5000);
digitalWrite(BUZZER,HIGH);
count=0;
}*/
}