Skip to content

Commit 183bfac

Browse files
authored
Update ArduinoMatrixClock.ino
1 parent 576f99c commit 183bfac

File tree

1 file changed

+70
-58
lines changed

1 file changed

+70
-58
lines changed

ArduinoMatrixClock/ArduinoMatrixClock.ino

Lines changed: 70 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
Name: ArduinoMatrixClock.ino
33
Created: 16.01.2018 20:56:49
4-
Last rev.: 05.07.2019
4+
Last rev.: 15.08.2019
55
Version: 1.4
66
Author: Petan (www.mylms.cz)
77
*/
@@ -54,6 +54,7 @@ Date (D) and temperature (t) are set to 40. Date has priority. Temperature (t) w
5454
Date (D) and temperature (t) is set to 60. Date has priority. Time (T) and temperature (t) will not show
5555
0DDDDDDDDDD DDDDDDDDDD DDDDDDDDDD DDDDDDDDDD DDDDDDDDDD DDDDDDDDDD60 second
5656
57+
5758
SHOW MESSAGE
5859
In v1.4 you can show some message (only 4 chars). If you connect input 10 and/or 11 to GND you can show one of them.
5960
Text of message you can upgrade only in this code, see row around 400 (look for '//show some message or time').
@@ -64,6 +65,7 @@ IN10 | IN11 | OUT
6465
1 | 0 | message 2
6566
1 | 1 | message 3
6667
68+
6769
SERIAL COMMUNICATION (9600b)
6870
You have to send three chars. 1st is function, other two are digits
6971
XNN -> X = function; NN = number 00 to 99 (two digits are nessesary)
@@ -87,22 +89,23 @@ b = brightness (0 - 15)
8789
f = font (1 - 5)
8890
/ = 12/24 hour format (/00 = 12h; /01 = 24h)
8991
: = dot style (:00 = not shown; :01 = always lit; :02 = blinking)
90-
v = vertical mode (v00 = standard horizontal; v01 = vertical mode)
92+
v = vertical mode (v00 = standar horizontal; v01 = vertical mode)
9193
9294
*/
9395

9496
#include <EEPROM.h>
9597
#include <Wire.h>
9698
#include <LedControl.h>
9799

100+
//YOU CAN CHANGE THIS VALUE TO CHANGE SHOWN TEMPERATURE - IT'S ONLY TEMPERATURE OFFSET
101+
//Example: Real temperature is 23°C. Clock shows 26°C. Difference is -3°C. You have to change value to 100 - 3 = 97
102+
const byte temperatureOffset = 97; //99 = -1, 100 = 0, 101 = 1 (only integer values)
103+
104+
98105
//OTHERS
99106
const byte versionMajor = 1;
100107
const byte versionMinor = 4;
101108

102-
//you can change this value to change shown temperature - it's only temperature offset
103-
//Example: Real temperature is 23°C. Clock shows 26°C. Difference is -3°C. You have to change value to 100 - 3 = 97
104-
const byte temperatureOffset = 97; //99 = -1, 100 = 0, 101 = 1
105-
106109
//MATRIX DISPLAY
107110
byte devices = 4; //count of displays
108111
LedControl lc = LedControl(4, 5, 6, devices); //DIN, CLK, CS, count of displays
@@ -124,6 +127,7 @@ unsigned long temperatureTime; //gat temp
124127
#define BTN2 3
125128
#define INPUT1 10
126129
#define INPUT2 11
130+
//How to detect signal rising/falling edge, see https://www.mylms.cz/kusy-kodu-k-arduinu/#edge_detection2
127131
bool presentButton1, presentButton2, presentInput1, presentInput2; //actual state of buttons and inputs
128132
bool lastButton1, lastButton2; //last state button s
129133
bool edgeButton1, edgeButton2; //edge state buttons
@@ -133,6 +137,7 @@ byte systemState; //0 = show time/date/temp, other = menu
133137
byte showMode = 0; //0 = time, 1 = date, 2 = temperature
134138
bool showDots; //dots are shown
135139
bool pmDotEnable = false; //pm dot is shown
140+
bool showText = false; //some user text is shown
136141

137142
//chars
138143
const uint64_t symbols[] = {
@@ -272,17 +277,16 @@ const uint64_t symbols[] = {
272277
#define char_v 55
273278
#define char_y 58
274279

275-
276280
byte fontCount = 5; //how many fonts is used
277281
byte fontOffset = 60; //count of symbols before 1st number
278282

279283
//default values...but they are load from EEPROM
280-
byte bright = 7;
284+
byte bright = 7; //brightness
281285
byte font = 1; //do not set less than 1. symbols 0-19 are used for letters etc.
282286
byte dotStyle = 2; //0 - off, 1 - on, 2 - blinking
283287
byte timeMode1224 = 1; //12/24 hour mode 12 = 0, 24 = 1
284-
byte rotateFont1 = 0; //font rotateing verticaly (one char)
285-
byte rotateFont2 = 0; //font rotateing verticaly (all display)
288+
byte rotateFont1 = 0; //font rotateing vertically (one char)
289+
byte rotateFont2 = 0; //font rotateing vertically (all display)
286290
byte showDate = 0; //how many second in one minute cycle is date shown
287291
byte showTemperature = 0; //how many second in one minute cycle is temperature shown
288292
byte upsideDown = 0; //us font Upside down
@@ -301,6 +305,7 @@ void setup() {
301305
pinMode(INPUT1, INPUT_PULLUP);
302306
pinMode(INPUT2, INPUT_PULLUP);
303307

308+
//LOAD DATA FROM EEPROM
304309
bright = EEPROM.read(0); //load light intensity from EEPROM
305310
if (bright < 0 || bright > 15) {
306311
//in case variable out of range
@@ -410,10 +415,13 @@ void loop() {
410415
displayTime = presentTime;
411416
GetRtc(); //get actual time
412417

413-
//show some message or time
418+
ToggleMode(); //toggle mode time/date/temperature
419+
420+
//show message or time
414421
if (presentInput1 && !presentInput2) {
415422
//IN1 = 1, IN2 = 0
416423
//MESSAGE 1 - blank display
424+
showText = true; //turn off colon, comma etc
417425
DrawSymbol(3, char_space); //space
418426
DrawSymbol(2, char_space); //space
419427
DrawSymbol(1, char_space); //space
@@ -422,6 +430,7 @@ void loop() {
422430
else if (!presentInput1 && presentInput2) {
423431
//IN1 = 0, IN2 = 1
424432
//MESSAGE 1 - LMS!
433+
showText = true; //turn off colon, comma etc
425434
DrawSymbol(3, char_L); //L
426435
DrawSymbol(2, char_M); //M
427436
DrawSymbol(1, char_S); //S
@@ -430,6 +439,7 @@ void loop() {
430439
else if (presentInput1 && presentInput2) {
431440
//IN1 = 1, IN2 = 1
432441
//MESSAGE 2 - version
442+
showText = true; //turn off colon, comma etc
433443
DrawSymbol(3, char_v); //v
434444
DrawSymbol(2, versionMajor + fontOffset);
435445
DrawSymbol(1, char_dot); //:
@@ -438,22 +448,22 @@ void loop() {
438448
else {
439449
//IN1 = 0, IN2 = 0
440450
//show time (or date, etc.)
451+
showText = false; //turn on colon, comma etc
441452
WriteTime(); //write actual time (etc) to matrix display
442453
}
443454

444455
}
445456

446457
if (presentButton1 && presentButton2) {
447-
systemState = 1;
448-
//go to "pre"menu
458+
systemState = 1; //go to "premenu"
449459
}
450460
break;
451461

452462
case 1:
453463
if (!presentButton1 && !presentButton2) {
454464
//NEXT
455-
GetRtc(); //get actual time (read time in 24h format - in menu is always 24h time format)
456-
systemState++; //Go to menu
465+
GetRtc(); //get actual time (read time in 24h format - in menu is always 24h time format used)
466+
systemState++; //go to menu
457467
DrawSymbol(3, char_space); //space
458468
DrawSymbol(2, char_space); //space
459469
DrawSymbol(1, char_space); //space
@@ -468,7 +478,6 @@ void loop() {
468478

469479
if (edgeButton1) {
470480
//rising edge detected
471-
472481
//NEXT
473482
systemState++;
474483
DrawSymbol(3, char_M); //M
@@ -494,7 +503,6 @@ void loop() {
494503

495504
if (edgeButton1) {
496505
//rising edge detected
497-
498506
//NEXT
499507
systemState++;
500508
DrawSymbol(3, char_y); //y
@@ -518,7 +526,6 @@ void loop() {
518526
//set YEAR
519527
if (edgeButton1) {
520528
//rising edge detected
521-
522529
//NEXT
523530
systemState++;
524531
DrawSymbol(3, char_m); //m
@@ -854,7 +861,7 @@ void loop() {
854861
case 14:
855862
//menu 14
856863
//set rotate FONT 2
857-
//Rotate all display (verticaly)
864+
//Rotate all display (vertically)
858865
if (edgeButton1) {
859866
//rising edge detected
860867

@@ -977,41 +984,14 @@ void loop() {
977984
}
978985

979986
void WriteTime() {
980-
byte storedFont = font; //store actual seting during MENU
987+
byte storedFont = font; //store actual setting during MENU
981988

982989
if (systemState > 0) {
983990
//reserve font for menu
984991
font = 1;
985992
}
986993

987-
if (second == 0) {
988-
//show time in 0 second
989-
showMode = 0;
990-
}
991-
992-
if (second == showTemperature && showTemperature > 0) {
993-
//showtemp is now & showtemp is enabled
994-
showMode = 2;
995-
}
996-
997-
if (second == showDate && showDate > 0) {
998-
//showdate is now & showdate is enabled
999-
//date has priority
1000-
showMode = 1;
1001-
}
1002-
1003-
if (showTemperature == 60) {
1004-
//salways howtemp
1005-
showMode = 2;
1006-
}
1007-
1008-
if (showDate == 60) {
1009-
//always show date
1010-
//date has priority
1011-
showMode = 1;
1012-
}
1013-
1014-
//write time to matrix display in menu
994+
//write hour to matrix display in menu
1015995
if (systemState == 2) {
1016996
//show hours in 24h format in menu (set hours)
1017997
DrawSymbol(2, (hour % 10) + (font * 10) + fontOffset - 10);
@@ -1021,7 +1001,7 @@ void WriteTime() {
10211001
pmDotEnable = false; //hide PM dot
10221002
}
10231003

1024-
//write time to matrix display in menu
1004+
//write minute to matrix display in menu
10251005
if (systemState == 3) {
10261006
//show minute in menu
10271007
DrawSymbol(0, (minute % 10) + (font * 10) + fontOffset - 10);
@@ -1125,6 +1105,36 @@ void WriteTime() {
11251105
font = storedFont;
11261106
}
11271107

1108+
void ToggleMode() {
1109+
if (second == 0) {
1110+
//show time in 0 second
1111+
showMode = 0;
1112+
}
1113+
1114+
if (second == showTemperature && showTemperature > 0) {
1115+
//showtemp is now & showtemp is enabled
1116+
showMode = 2;
1117+
}
1118+
1119+
if (second == showDate && showDate > 0) {
1120+
//showdate is now & showdate is enabled
1121+
//date has priority
1122+
showMode = 1;
1123+
}
1124+
1125+
if (showTemperature == 60) {
1126+
//salways howtemp
1127+
showMode = 2;
1128+
}
1129+
1130+
if (showDate == 60) {
1131+
//always show date
1132+
//date has priority
1133+
showMode = 1;
1134+
}
1135+
}
1136+
1137+
11281138
void Intro() {
11291139
DrawSymbol(3, char_L); //L
11301140
DrawSymbol(2, char_M); //M
@@ -1147,33 +1157,34 @@ void DrawSymbol(byte adr, byte symbol) {
11471157
adr = 3 - adr;
11481158
}
11491159

1150-
byte j = 0; //variable for upsidedown font turning
1160+
byte j = 0; //variable for upside-down font turning
11511161

11521162
for (byte i = 0; i < 8; i++) {
11531163
j = i;
11541164
if (upsideDown == 1) {
1155-
//turn font upside down
1165+
//turn font upside down, if it's enabled
11561166
j = 7 - i;
11571167
}
11581168

1159-
byte row = (symbols[symbol] >> i * 8) & 0xFF; //just some magic
1169+
byte row = (symbols[symbol] >> i * 8) & 0xFF; //just some magic - extract one row from all symbol
11601170

11611171
if (verticalMode == 1) {
11621172
//vertical mode
11631173
lc.setColumn(adr, j, ByteRevers(row));
11641174

11651175
//blinking dots on display
11661176
//I have to draw "dots" during draw symbol. In other case it's blinking.
1177+
//all "dots" are disabled in show text mode
11671178
//Better variant would update symbol before draw - before FOR structure. Maybe in next version :)
1168-
if (adr == 2 && dotStyle > 0 && i == 7) {
1179+
if (adr == 2 && dotStyle > 0 && i == 7 && !showText) {
11691180
//colon
11701181
lc.setLed(adr, 1, 7, showDots); //addr, row, column
11711182
lc.setLed(adr, 2, 7, showDots);
11721183
lc.setLed(adr, 5, 7, showDots);
11731184
lc.setLed(adr, 6, 7, showDots);
11741185
}
11751186

1176-
if (adr == 2 && systemState == 0 && (showMode == 1 || showMode == 2)) {
1187+
if (adr == 2 && systemState == 0 && (showMode == 1 || showMode == 2) && !showText) {
11771188
//date and temperature point
11781189
lc.setLed(adr, 1, 7, true);
11791190
lc.setLed(adr, 2, 7, true);
@@ -1185,31 +1196,32 @@ void DrawSymbol(byte adr, byte symbol) {
11851196

11861197
//blinking dots on display
11871198
//I have to draw "dots" during draw symbol. In other case it's blinking.
1199+
//all "dots" are disabled in show text mode
11881200
//Better variant would update symbol before draw - before FOR structure. Maybe in next version :)
1189-
if (adr == 2 && dotStyle > 0) {
1201+
if (adr == 2 && dotStyle > 0 && !showText) {
11901202
//colon
11911203
if (i == 1) lc.setLed(adr, 1, 7, showDots); //addr, row, column
11921204
if (i == 2) lc.setLed(adr, 2, 7, showDots);
11931205
if (i == 5) lc.setLed(adr, 5, 7, showDots);
11941206
if (i == 6) lc.setLed(adr, 6, 7, showDots);
11951207
}
11961208

1197-
if (adr == 2 && systemState == 0 && (showMode == 1 || showMode == 2)) {
1209+
if (adr == 2 && systemState == 0 && (showMode == 1 || showMode == 2) && !showText) {
11981210
//date and temperature point
11991211
if (i == 5) lc.setLed(adr, 5, 7, true);
12001212
if (i == 6) lc.setLed(adr, 6, 7, true);
12011213
}
12021214
}
12031215

1204-
if (adr == 0) {
1216+
if (adr == 0 && !showText) {
12051217
//PM point
12061218
lc.setLed(0, 7, 7, pmDotEnable);
12071219
}
12081220
}
12091221
}
12101222

12111223
byte ByteRevers(byte in) {
1212-
//font rotateing
1224+
//font rotating
12131225
if ((rotateFont1 == 1 && verticalMode == 0) || (rotateFont1 == 0 && verticalMode == 1)) {
12141226
//do not rotate
12151227
return(in);

0 commit comments

Comments
 (0)