4
4
#include < Wire.h>
5
5
6
6
const int hourPins[] = {2 , 3 , 4 , 5 , 6 };
7
- const int minutePins[] = {7 , 8 , 9 , 10 , 11 , 12 };
8
- const int secondPin = 13 ;
9
- const bool blinkSecondPin = true ;
7
+ const int minutePins[] = {7 , 8 , 9 , 14 , 15 , 16 };
8
+ const int secondRed = 10 ;
9
+ const int secondGreen = 11 ;
10
+ const int secondBlue = 12 ;
11
+ const bool blinkSecondPins = true ;
10
12
int amountOfMinutePins = 6 ;
11
13
int amountOfHourPins = 5 ;
12
14
int previousSecond = 0 ;
13
15
int previousMinute = 0 ;
14
16
int previousHour = 0 ;
15
17
16
18
void setup () {
19
+ Serial.begin (9600 );
17
20
setSyncProvider (RTC.get );
18
21
setSyncInterval (100 );
19
22
@@ -24,15 +27,19 @@ void setup() {
24
27
for (i = 0 ; i < amountOfMinutePins ; i++){
25
28
initOutputPin (minutePins[i]);
26
29
}
27
- initOutputPin (secondPin);
30
+ pinMode (secondRed, OUTPUT);
31
+ pinMode (secondGreen, OUTPUT);
32
+ pinMode (secondBlue, OUTPUT);
33
+
28
34
updateMinutes (minute ());
29
35
updateHours (hour ());
36
+ updateSecondColor (second ());
30
37
}
31
38
32
39
void loop () {
33
40
int curSec = second ();
34
41
if ((previousSecond < curSec) || (previousSecond > curSec && previousSecond == 59 )){
35
- toggleSecondPin ( );
42
+ toggleSecondPins (curSec );
36
43
previousSecond = curSec;
37
44
}
38
45
int curMin = minute ();
@@ -81,10 +88,44 @@ void updateHours(int hrs){
81
88
}
82
89
}
83
90
84
- void toggleSecondPin (){
85
- if (blinkSecondPin){
86
- togglePin (secondPin);
91
+ void toggleSecondPins (int seconds){
92
+ if (seconds % 2 == 0 ) {
93
+ writeSecondColor (0 ,0 ,0 );
94
+ } else {
95
+ updateSecondColor (seconds);
96
+ }
97
+ }
98
+
99
+ void updateSecondColor (int seconds){
100
+ int red = 0 ;
101
+ int green = 0 ;
102
+ int blue = 0 ;
103
+ if (seconds <= 21 ){
104
+ blue = seconds*2 ;
105
+ } else if (seconds <= 41 ){
106
+ red = seconds;
107
+ blue = 41 - seconds;
108
+ } else {
109
+ red = 60 - seconds;
110
+ green = seconds;
87
111
}
112
+ Serial.print (" Second: " );
113
+ Serial.print (seconds);
114
+ Serial.print (" , red: " );
115
+ Serial.print (red);
116
+ Serial.print (" , green: " );
117
+ Serial.print (green);
118
+ Serial.print (" , blue: " );
119
+ Serial.print (blue);
120
+ Serial.println (" " );
121
+
122
+ writeSecondColor (red, green, blue);
123
+ }
124
+
125
+ void writeSecondColor (int red, int green, int blue){
126
+ analogWrite (secondRed, red);
127
+ analogWrite (secondGreen, green);
128
+ analogWrite (secondBlue, blue);
88
129
}
89
130
90
131
void togglePin (int pinNumber){
0 commit comments