This is binary clock that I created around Mini Pro and RTC 3231. First 2 columns(from the left)-hours, next 2 minutes, and the last 2 temperature. RTC3231 has built in Temperature sensor.
I use multiplexing for displaying as there are not enough IO pins for connecting. The projects works flawles. No flickering either.
I will appreciate any improvement suggestions as I am not a programmer and not sure if things done this way.
/*Binaryclock using multiplexing by systemGamer Mannheim 20200522
V3.0 This version also incorporates room temperature reading instead of seconds section
+
o o o 2
o o o o o 3
o o o o o o 5
o o o o o o 4
6 7 8 9 10 11 -
*/
#include "RTClib.h"
RTC_DS3231 rtc;
void setup() {
#ifndef ESP8266
while (!Serial); // for Leonardo/Micro/Zero
#endif
Serial.begin(9600);
if (! rtc.begin()) {
Serial.println("Couldn't find RTC");
while (1);
}
for (int ttl = 2; ttl < 12; ttl++) {
pinMode(ttl, OUTPUT);
}
}
int row[4] = {5, 4, 3, 2};
int column[6] = {6, 7, 8, 9, 10, 11};
byte rowState = B00000000;
byte columnState = B00000001;//scan throgh columns with this one
byte section[6];
int a = 0;
void loop() {
updateSection(a);
updateLeds();
a++;
columnState = columnState << 1;
if (columnState == 64) {
columnState = 1;
}
if (a == 6) {
a = 0;
}
}
void updateSection(int a) {
DateTime now = rtc.now();
int hour1 = now.hour();
section[0] = (hour1 / 10);
section[1] = (hour1 % 10);
int minute1 = now.minute();
section[2] = (minute1 / 10);
section[3] = (minute1 % 10);
int temperature = rtc.getTemperature();
section[4] = (temperature / 10);
section[5] = (temperature % 10);
rowState = section[a];
}
void updateLeds() {
for (int ttl = 0; ttl < 4; ttl++) { // set first 4 bits of rowState to rows
digitalWrite(row[ttl], bitRead(rowState, ttl));
}
for (int ttl = 0; ttl < 6; ttl++) { // set first 6 bits of rowState to rows
digitalWrite(column[ttl], bitRead(~columnState, ttl));
}
}