The real-time clock is nice to have, but what if you cannot read it? Well, if you shrink the character set (figures only) to just 3 by 5 you can show four figures (time hh:mm or date dd:MM) on the 8 by 12 LED matrix when you rotate the board by 90 degrees.
Unfortunately, the contrast of the display is not always what you want.
And this is the code:
/*
Die teuerste Uhr der Welt
Zeichenanzeige auf Matrix:
https://arduinogetstarted.com/tutorials/arduino-uno-r4-led-matrix-displays-number-character
*/
#include <RTC.h>
RTCTime currentTime;
// UNO-R4 Wifi LED Matrix:
#include "Arduino_LED_Matrix.h"
#include "fonts.h"
ArduinoLEDMatrix matrix;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
while (!Serial)
;
delay(1500);
Serial.println(__FILE__);
// a lot of work to extract HMS from __TIME__:
// hour
char time[] = __TIME__;
char temp[8];
strncpy(temp, time, 2);
int h = atoi(temp);
// minute:
memset(time, ' ', 3);
strncpy(temp, time, 5);
int m = atoi(temp);
// second:
memset(time, ' ', 6);
int s = atoi(time);
// RTC:
RTC.begin();
/*
name of month, day of week, and saveLight
are not shown and therefore ignored
*/
RTCTime startTime(1, Month::JANUARY, 13, h, m, s, DayOfWeek::MONDAY, SaveLight::SAVING_TIME_ACTIVE);
RTC.setTime(startTime);
matrix.begin();
}
void loop() {
int h10, h01, m10, m01, s10, s01;
// Get current time from RTC
RTC.getTime(currentTime);
int hour = currentTime.getHour();
int minute = currentTime.getMinutes();
int seconds = currentTime.getSeconds();
Serial.print(hour);
Serial.print(":");
Serial.print(minute);
Serial.print(":");
Serial.println(seconds);
h10 = hour / 10;
h01 = hour % 10;
m10 = minute / 10;
m01 = minute % 10;
s10 = seconds / 10;
s01 = seconds % 10;
clear_frame();
// Matrix row/col Hochformat
// row: links 7, rechts 0
// col: oben 0, unten 11
add_to_frame(h10, 5, 0);
add_to_frame(h01, 1, 0);
add_to_frame(m10, 5, 6);
add_to_frame(m01, 1, 6);
display_frame();
delay(5000);
}
uint8_t frame[8][12];
void clear_frame() {
for (int row = 0; row < 8; row++) {
for (int col = 0; col < 12; col++) {
frame[row][col] = 0;
}
}
}
void display_frame() {
matrix.renderBitmap(frame, 8, 12);
}
void add_to_frame(int index, int x, int y) {
for (int row = 0; row < 5; row++) {
uint32_t temp = fonts[index][row + 1];
Serial.print(index);
Serial.print(" ");
Serial.println(0x100 + temp, BIN);
for (int col = 0; col < 3; col++)
frame[x + col][y + row] |= (temp >> col) & 1;
}
}
And
this is the character set:
/*
shrinked character set
*/
uint8_t fonts[][8] = {
{
// 0
0b000,
0b111,
0b101,
0b101,
0b101,
0b111,
0b000,
0b000,
},
{
// 1
0b000,
0b010,
0b110,
0b010,
0b010,
0b111,
0b000,
0b000,
},
{
// 2
0b000,
0b111,
0b001,
0b111,
0b100,
0b111,
0b000,
0b000,
},
{
// 3
0b000,
0b111,
0b001,
0b111,
0b001,
0b111,
0b000,
0b000,
},
{
// 4
0b000,
0b101,
0b101,
0b111,
0b001,
0b001,
0b000,
0b000,
},
{
// 5
0b000,
0b111,
0b100,
0b111,
0b001,
0b111,
0b000,
0b000,
},
{
// 6
0b000,
0b111,
0b100,
0b111,
0b101,
0b111,
0b000,
0b000,
},
{
// 7
0b000,
0b111,
0b001,
0b001,
0b001,
0b001,
0b000,
0b000,
},
{
// 8
0b000,
0b111,
0b101,
0b111,
0b101,
0b111,
0b000,
0b000,
},
{
// 9
0b000,
0b111,
0b101,
0b111,
0b001,
0b111,
0b000,
0b000,
},
};
The time is set on the minute you upload the code. Keep in mind: before you disconnect the power, add a 3 volts cell to the extra pins VRTC and GND. See https://docs.arduino.cc/tutorials/uno-r4-wifi/vrtc-off for details.
Comments