Skip to content

Commit 22d3d18

Browse files
Add support for RGB second blinker
1 parent 6a19997 commit 22d3d18

File tree

1 file changed

+49
-8
lines changed

1 file changed

+49
-8
lines changed

Binary_clock.ino

+49-8
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,19 @@
44
#include <Wire.h>
55

66
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;
1012
int amountOfMinutePins = 6;
1113
int amountOfHourPins = 5;
1214
int previousSecond = 0;
1315
int previousMinute = 0;
1416
int previousHour = 0;
1517

1618
void setup() {
19+
Serial.begin(9600);
1720
setSyncProvider(RTC.get);
1821
setSyncInterval(100);
1922

@@ -24,15 +27,19 @@ void setup() {
2427
for (i = 0; i < amountOfMinutePins ; i++){
2528
initOutputPin(minutePins[i]);
2629
}
27-
initOutputPin(secondPin);
30+
pinMode(secondRed, OUTPUT);
31+
pinMode(secondGreen, OUTPUT);
32+
pinMode(secondBlue, OUTPUT);
33+
2834
updateMinutes(minute());
2935
updateHours(hour());
36+
updateSecondColor(second());
3037
}
3138

3239
void loop() {
3340
int curSec = second();
3441
if ((previousSecond < curSec) || (previousSecond > curSec && previousSecond == 59)){
35-
toggleSecondPin();
42+
toggleSecondPins(curSec);
3643
previousSecond = curSec;
3744
}
3845
int curMin = minute();
@@ -81,10 +88,44 @@ void updateHours(int hrs){
8188
}
8289
}
8390

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;
87111
}
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);
88129
}
89130

90131
void togglePin(int pinNumber){

0 commit comments

Comments
 (0)