Digital Clock with Arduino Uno Rev4 WiFi's RTC an LED Matrix
Building a clock with just a microcontroller board. As all needed components like RTC and LED matrix are already built in.
Components and supplies
1
Arduino R4 WIFI
Apps and platforms
1
Arduino IDE 2.0 (beta)
Project description
Code
Code to display time on built-in LED matrix of Arduino Uno R4 matrix
cpp
Watch video tutorial
1#include "RTC.h" 2#include "Arduino_LED_Matrix.h" 3ArduinoLEDMatrix matrix; 4 5byte Time[8][12] = { 6 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, 7 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, 8 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, 9 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, 10 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, 11 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, 12 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, 13 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} 14}; 15 16byte Digits [5][30]{ 17{ 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, 18{ 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 1, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 1 }, 19{ 1, 0, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1 }, 20{ 1, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1 }, 21{ 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1 }, 22}; 23 24 25int currentSecond; 26boolean secondsON_OFF = 1; 27int hours, minutes, seconds, year, dayofMon; 28String dayofWeek, month; 29 30void displayDigit(int d, int s_x, int s_y){ 31 for (int i=0;i<3;i++) 32 for (int j=0;j<5;j++) 33 Time[i+s_x][11-j-s_y] = Digits[j][i+d*3]; 34 35 matrix.renderBitmap(Time, 8, 12); 36} 37 38 39DayOfWeek convertDOW(String dow){ 40 if (dow == String("Mon")) return DayOfWeek::MONDAY; 41 if (dow == String("Tue")) return DayOfWeek::TUESDAY; 42 if (dow == String("Wed")) return DayOfWeek::WEDNESDAY; 43 if (dow == String("Thu")) return DayOfWeek::THURSDAY; 44 if (dow == String("Fri")) return DayOfWeek::FRIDAY; 45 if (dow == String("Sat")) return DayOfWeek::SATURDAY; 46 if (dow == String("Sun")) return DayOfWeek::SUNDAY; 47} 48 49Month convertMonth(String m){ 50 if (m == String("Jan")) return Month::JANUARY; 51 if (m == String("Feb")) return Month::FEBRUARY; 52 if (m == String("Mar")) return Month::MARCH; 53 if (m == String("Apr")) return Month::APRIL; 54 if (m == String("May")) return Month::MAY; 55 if (m == String("Jun")) return Month::JUNE; 56 if (m == String("Jul")) return Month::JULY; 57 if (m == String("Aug")) return Month::AUGUST; 58 if (m == String("Sep")) return Month::SEPTEMBER; 59 if (m == String("Oct")) return Month::OCTOBER; 60 if (m == String("Nov")) return Month::NOVEMBER; 61 if (m == String("Dec")) return Month::DECEMBER; 62} 63 64void getCurTime(String timeSTR,String* d_w,int* d_mn, String* mn,int* h,int* m,int* s,int* y){ 65 66 *d_w = timeSTR.substring(0,3); 67 *mn = timeSTR.substring(4,7); 68 *d_mn = timeSTR.substring(8,11).toInt(); 69 *h = timeSTR.substring(11,13).toInt(); 70 *m = timeSTR.substring(14,16).toInt(); 71 *s = timeSTR.substring(17,19).toInt(); 72 *y = timeSTR.substring(20,24).toInt(); 73 74} 75 76 77void setup() { 78 Serial.begin(9600); 79 matrix.begin(); 80 RTC.begin(); 81 String timeStamp = __TIMESTAMP__; 82 getCurTime(timeStamp,&dayofWeek,&dayofMon,&month,&hours,&minutes,&seconds,&year); 83 RTCTime startTime(dayofMon, convertMonth(month) , year, hours, minutes, seconds, 84 convertDOW(dayofWeek), SaveLight::SAVING_TIME_ACTIVE); 85 RTC.setTime(startTime); 86} 87 88void loop(){ 89 RTCTime currentTime; 90 RTC.getTime(currentTime); 91 if (currentTime.getSeconds()!=currentSecond){ 92 secondsON_OFF ? secondsON_OFF = 0 : secondsON_OFF = 1; 93 displayDigit((int)(currentTime.getHour()/10),0,0 ); 94 displayDigit(currentTime.getHour()%10,4,0 ); 95 displayDigit((int)(currentTime.getMinutes()/10),1,6 ); 96 displayDigit(currentTime.getMinutes()%10,5,6 ); 97 Time[0][2]=secondsON_OFF; 98 Time[0][4]=secondsON_OFF; 99 currentSecond=currentTime.getSeconds(); 100 matrix.renderBitmap(Time, 8, 12); 101 Serial.println(secondsON_OFF); 102 } 103}
Comments
Only logged in users can leave comments