// https://forum.arduino.cc/t/bool-array-memory-usage/1440561
#include <FastLED.h> // https://github.com/FastLED/FastLED
// calculated pixels
#define DIGIT 4 // 12:34 digits per display
#define SEGMENT 7 // ABCDEFG segments per digit
#define SEGPIX 9 // 000000000 pixels per segment
#define COLON 2 // : colon dots
#define DIGPIX SEGMENT * SEGPIX // pixels per digit
#define NUMPIX DIGIT * SEGMENT * SEGPIX + COLON
#define DATAPIN 12
#define MAXBRIGHT 255
CRGB led[NUMPIX];
#include <RTClib.h>
RTC_DS1307 rtc;
int digCount, segCount, segPix, colon;
int hours, minutes, seconds, oldSeconds;
void setup() {
Serial.begin(115200);
rtc.begin();
// rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
// setTime(h, m, s, d, mm, yyyy);
FastLED.addLeds<WS2812B, DATAPIN, GRB>(led, NUMPIX);
FastLED.setBrightness(MAXBRIGHT);
FastLED.clear();
FastLED.show();
}
void loop() {
DateTime now = rtc.now(); // "now" is local to loop()
hours = now.hour();
minutes = now.minute();
seconds = now.second();
if (seconds != oldSeconds) {
oldSeconds = seconds;
clock();
// showpixels(255 * random(2), 255 * random(2), 255 * random(2));
// showsegments(255, 0, 0);
}
}
void clock() {
int hours_tens = hours / 10;
int hours_unit = hours % 10;
int minutes_tens = minutes / 10;
int minutes_unit = minutes % 10;
Serial.print(hours_tens);
Serial.print(hours_unit);
Serial.print(":");
Serial.print(minutes_tens);
Serial.print(minutes_unit);
Serial.println();
}
void showsegments(int red, int grn, int blu) {
if (segCount == SEGMENT) {
segCount = 0;
digCount++;
if (digCount > 1) {
colon = 2; // add two pixels for colon
}
if (digCount == DIGIT) {
digCount = 0;
colon = 0;
FastLED.clear();
FastLED.show();
}
}
for (int segPix = 0; segPix < SEGPIX; segPix++) { // segment pixels
led[(digCount * DIGPIX) + (segCount * SEGPIX) + segPix + colon] = CRGB(red, grn, blu); // individual pixels
}
FastLED.show(); // show after segment is in buffer
segCount++;
}
void showpixels(int red, int grn, int blu) {
for (int i = 0; i < NUMPIX; i++) {
led[i] = CRGB(red, grn, blu);
delay(10);
FastLED.show();
}
delay(2000);
FastLED.clear();
FastLED.show();
}