#include <FastLED.h> // https://github.com/FastLED/FastLED
#define ROWS 16 // matrix rows
#define COLS 16 // matrix columns
#define NUMPIX (ROWS * COLS) // the full matrix
#define PIXPIN 5 // Arduino data/digital pin
#define MAXBRIGHT 255 // pixels brightness, 0 - 255
CRGB pix[NUMPIX]; // create object to control [NUMPIX]
#include <RTClib.h>
RTC_DS1307 rtc;
#include "words.h" // words in the clock
#include "showMin.h" // show minutes
#include "showHour.h" // show hours
// #include "tests.h" // test functions for letter and word placement
unsigned long timer, ms1000 = 1000; // one second
int oldMin; // clear old time
void setup() {
// Serial.begin(115200); // enable for testing
FastLED.addLeds<WS2812B, PIXPIN, GRB>(pix, NUMPIX);
FastLED.setBrightness(MAXBRIGHT);
FastLED.clear(); // empty pixel buffer
FastLED.show(); // display empty buffer
if (! rtc.begin()) {
Serial.println(F("ERROR reading RTC"));
Serial.flush();
while (1);
}
// TIME FUNCTIONS
// rtc.adjust(DateTime(F(__DATE__), F(__TIME__))); // run once after inserting new battery
// rtc.adjust(DateTime (2000, 1, 2, 3, 4, 56)); // adjustable time for testing
// rtc.adjust(DateTime(year, month, date, hour, minute, second));
// TEST FUNCTIONS
// sayall(); while (1); // un-comment test.h... test all words then halt
// lightall(); while (1); // un-comment test.h... test all LEDs then halt
}
void loop () {
if (millis() - timer > ms1000) { // update every second
timer = millis(); // reset timer
// gettimedate(); // print time and date text in Serial Monitor with external function
DateTime now = rtc.now(); // get local time and date
// UPDATE ONLY AT TOP OF MINUTE
if (now.minute() != oldMin) { // check for minute change
oldMin = now.minute(); // store new minute
FastLED.clear(); // clear previous clock reading
}
the(); tim(); is(); // these words will always be on
// CALCULATE MINUTES, UNTIL, PAST
if (now.minute() > 0) { // only show "minutes" after "zero"
if (now.minute() >= 20 && now.minute() < 30) { // 21 through 29 becomes "twenty" (min) "past"
twnty();
showMin(now.minute() - 20); // subtract 20 from 21..29 = minutes
}
if (now.minute() == 30) { // exactly 30
hlf(); pst(); // "half" "past"
}
if (now.minute() > 30 && now.minute() <= 40) { // 31 through 39 becomes "twenty" (min) "until"
twnty();
showMin(40 - now.minute()); // subtract 31..39 from 60 = minutes
}
if (now.minute() != 15 && now.minute() != 45 && now.minute() != 30) {
if (now.minute() == 1 || now.minute() == 59)
minx(); // minute. - singular
else
mins(); // minutes - plural
}
if (now.minute() < 30) pst(); // before half
if (now.minute() > 30) { // after half
if (now.minute() == 45) // quarter (hour)
til(); // shortened 'til
else
utl(); // until
}
if ((now.minute() != 15) && (now.minute() != 45)) { // exclude "quarter" hours
if (now.minute() > 40) showMin(60 - now.minute()); // minutes 41 to 59 "until"
if (now.minute() < 20) showMin(now.minute()); // minutes 1 to 19 "past"
} else if ((now.minute() == 15) || (now.minute()) == 45)
qrtr(); // 15 "quarter"
}
// MAKE 12-HOUR CLOCK - replace two checks on now.hour() == 11 and now.hour() == 23
// int tHour = (now.hour() < 13) ? now.hour() : now.hour() - 12;
// PAST (the hour) and UNTIL (the hour)
if (now.minute() > 30)
showHour(now.hour() + 1); // add an hour if "until the hour"
else
showHour(now.hour());
// MIDNIGHT (0 or 24) and NOON (12)
if (now.hour() == 0 && !(now.minute() > 30))
showHour(0); // "midnight"
else if (now.hour() == 12 && !(now.minute() > 30))
showHour(12); // "noon"
// O'CLOCK not after NOON and MIDNIGHT
if (!((now.minute() > 30 && (now.hour() == 11 || now.hour() == 23) || // 31 TO 59
(now.minute() < 30 && (now.hour() == 12 || now.hour() == 0))))) { // 1 TO 29
ocl(); // o'clock
}
// AM or PM (ANTE MERIDIAM / POST MERIDIAM) following O'CLOCK
if (now.hour() > 12 && !(now.minute() > 30 && now.hour() == 23)) // no PM at NOON
pm();
else if (now.hour() < 12 && !(now.minute() > 30 && now.hour() == 11)) {
am();
}
}
}
X
T
T
F
N
D
F
S
E
Q
H
O
D
D
C
O
T
W
H
S
I
T
O
I
I
U
A
N
F
E
E
'
H
E
R
I
N
W
U
X
G
A
L
E
I
I
L
C
E
N
E
X
E
E
R
T
H
R
F
T
V
G
E
L
F
T
E
P
W
L
T
E
T
T
K
W
E
H
V
O
P
Y
C
S
T
V
E
E
E
E
U
O
W
T
E
C
T
D
F
E
E
E
E
N
E
R
N
T
S
C
N
K
I
O
O
V
N
C
N
S
N
O
T
H
I
N
K
!
M
N
U
E
O
T
L
E
N
M
I
R
X
I
M
P
E
E
R
N
E
H
F
V
I
I
L
E
O
N
I
M
D
C
K
D
L
I
I
E
N
N
X
E
S
E
D
A
W
T
F
E
E
R
F
N
E
U
P
F
E
L
N
M
I
W
I
I
V
T
T
T
T
T
A
O
V
T
I
N
S
O
V
G
E
E
E
E
E
E
S
U
E
E
G
O
O
L
E
H
N
E
E
E
E
S
T
R
N
N
H
O
R
O
X
T
R
N
N
N
N
C
F
P
R
O
T
N