└── MAX7219 LED Matrix Clock ├── Clock Code.txt ├── README.txt ├── Schematic.jpg └── set RTC time code.txt /MAX7219 LED Matrix Clock/Clock Code.txt: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "Font_Data.h" 5 | #include 6 | #include 7 | DS3231 Clock; 8 | 9 | bool Century=false; 10 | bool h12; 11 | bool PM; 12 | byte dd,mm,yyy; 13 | uint16_t h, m, s; 14 | 15 | #define MAX_DEVICES 4 16 | #define HARDWARE_TYPE MD_MAX72XX::FC16_HW 17 | #define CLK_PIN 13 18 | #define DATA_PIN 11 19 | #define CS_PIN 10 20 | MD_Parola P = MD_Parola(HARDWARE_TYPE,CS_PIN, MAX_DEVICES); 21 | 22 | #define SPEED_TIME 75 23 | #define PAUSE_TIME 0 24 | 25 | #define MAX_MESG 20 26 | 27 | char szTime[9]; 28 | char szMesg[MAX_MESG+1] = ""; 29 | 30 | uint8_t degC[] = { 6, 3, 3, 56, 68, 68, 68 }; 31 | uint8_t degF[] = { 6, 3, 3, 124, 20, 20, 4 }; 32 | 33 | char *mon2str(uint8_t mon, char *psz, uint8_t len) 34 | 35 | 36 | { 37 | static const __FlashStringHelper* str[] = 38 | { 39 | F("Jan"), F("Feb"), F("Mar"), F("Apr"), 40 | F("May"), F("Jun"), F("Jul"), F("Aug"), 41 | F("Sep"), F("Oct"), F("Nov"), F("Dec") 42 | }; 43 | 44 | strncpy_P(psz, (const char PROGMEM *)str[mon-1], len); 45 | psz[len] = '\0'; 46 | 47 | return(psz); 48 | } 49 | 50 | char *dow2str(uint8_t code, char *psz, uint8_t len) 51 | { 52 | static const __FlashStringHelper* str[] = 53 | { 54 | F("Sunday"), F("Monday"), F("Tuesday"), 55 | F("Wednesday"), F("Thursday"), F("Friday"), 56 | F("Saturday"), F("Sunday") 57 | }; 58 | 59 | strncpy_P(psz, (const char PROGMEM *)str[code-1], len); 60 | psz[len] = '\0'; 61 | 62 | return(psz); 63 | } 64 | void getTime(char *psz, bool f = true) 65 | { 66 | s = Clock.getSecond(); 67 | m = Clock.getMinute(); 68 | sprintf(psz, "%02d%c%02d", h, (f ? ':' : ' '), m); 69 | if (Clock.getHour(h12,PM)>=13 || Clock.getHour(h12,PM)==0) 70 | { 71 | h = Clock.getHour(h12,PM) - 12; 72 | } 73 | else 74 | { 75 | h = Clock.getHour(h12,PM); 76 | } 77 | 78 | } 79 | 80 | void getDate(char *psz) 81 | { 82 | char szBuf[10]; 83 | 84 | 85 | dd=Clock.getDate(); 86 | mm=Clock.getMonth(Century); 87 | yyy=Clock.getYear(); 88 | sprintf(psz, "%d %s %04d",dd , mon2str(mm, szBuf, sizeof(szBuf)-1),(yyy + 2000)); 89 | } 90 | 91 | void setup(void) 92 | { 93 | P.begin(2); 94 | P.setInvert(false); 95 | Wire.begin(); 96 | 97 | P.setZone(0, MAX_DEVICES-4, MAX_DEVICES-1); 98 | 99 | P.setZone(1, MAX_DEVICES-4, MAX_DEVICES-1); 100 | P.displayZoneText(1, szTime, PA_CENTER, SPEED_TIME, PAUSE_TIME, PA_PRINT, PA_NO_EFFECT); 101 | 102 | P.displayZoneText(0, szMesg, PA_CENTER, SPEED_TIME, 0,PA_PRINT , PA_NO_EFFECT); 103 | 104 | P.addChar('$', degC); 105 | P.addChar('&', degF); 106 | 107 | } 108 | 109 | void loop(void) 110 | { 111 | static uint32_t lastTime = 0; 112 | static uint8_t display = 0; 113 | static bool flasher = false; 114 | 115 | P.displayAnimate(); 116 | 117 | if (P.getZoneStatus(0)) 118 | { 119 | switch (display) 120 | { 121 | case 0: 122 | P.setPause(0,1000); 123 | P.setTextEffect(0, PA_MESH, PA_BLINDS); 124 | display++; 125 | dtostrf(Clock.getTemperature(), 3, 1, szMesg); 126 | strcat(szMesg, "$"); 127 | 128 | 129 | break; 130 | 131 | case 1: 132 | P.setTextEffect(0, PA_OPENING, PA_GROW_DOWN); 133 | display++; 134 | dtostrf((1.8 *Clock.getTemperature() )+32, 3, 1, szMesg); 135 | strcat(szMesg, "&"); 136 | 137 | 138 | 139 | break; 140 | 141 | case 2: 142 | 143 | P.setFont(0, numeric7Seg); 144 | P.setTextEffect(0, PA_PRINT, PA_NO_EFFECT); 145 | P.setPause(0,0); 146 | 147 | if (millis() - lastTime >= 1000) 148 | { 149 | lastTime = millis(); 150 | getTime(szMesg, flasher); 151 | flasher = !flasher; 152 | } 153 | if(s==00&& s<=30){ 154 | display++; 155 | P.setTextEffect(0, PA_PRINT, PA_SCROLL_UP); 156 | } 157 | 158 | 159 | 160 | break; 161 | 162 | case 3: 163 | 164 | P.setFont(0,nullptr); 165 | P.setTextEffect(0, PA_SCROLL_LEFT, PA_SCROLL_LEFT); 166 | display++; 167 | dow2str(Clock.getDoW()+1, szMesg, MAX_MESG); // Added +1 or +2 to get correct Day of Week 168 | 169 | 170 | break; 171 | default: 172 | 173 | P.setTextEffect(0, PA_SCROLL_LEFT, PA_SCROLL_LEFT); 174 | display = 0; 175 | getDate(szMesg); 176 | break; 177 | } 178 | 179 | P.displayReset(0); 180 | } 181 | 182 | } -------------------------------------------------------------------------------- /MAX7219 LED Matrix Clock/README.txt: -------------------------------------------------------------------------------- 1 | 2 | Required Libraries 3 | 4 | // MD Parola 3.0.1: https://github.com/MajicDesigns/MD_Parola 5 | // MD_MAX72XX 3.0.2: https://github.com/MajicDesigns/MD_MAX72XX 6 | // DS3231 1.0.2: https://github.com/NorthernWidget/DS3231 7 | 8 | 9 | First run the code - set RTC time code: This will set the time to RTC module 10 | Next run the code - Clock Code: This is the display code. 11 | 12 | Compile the code to make sure you install all the required libraries. -------------------------------------------------------------------------------- /MAX7219 LED Matrix Clock/Schematic.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/manjuhm/LED-Matrx-Clock/35f83254f077cf898f4c9ec9006b8932657de7c2/MAX7219 LED Matrix Clock/Schematic.jpg -------------------------------------------------------------------------------- /MAX7219 LED Matrix Clock/set RTC time code.txt: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | RTC_DS3231 rtc; 5 | 6 | char t[32]; 7 | 8 | void setup() 9 | { 10 | Serial.begin(9600); 11 | Wire.begin(); 12 | 13 | rtc.begin(); 14 | rtc.adjust(DateTime(F(__DATE__),F(__TIME__))); 15 | //rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0)); 16 | 17 | 18 | } 19 | 20 | void loop() 21 | { 22 | DateTime now = rtc.now(); 23 | 24 | sprintf(t, "%02d:%02d:%02d %02d/%02d/%02d", now.hour(), now.minute(), now.second(), now.day(), now.month(), now.year()); 25 | 26 | Serial.print(F("Date/Time: ")); 27 | Serial.println(t); 28 | 29 | delay(1000); 30 | } 31 | --------------------------------------------------------------------------------