Skip to content

Instantly share code, notes, and snippets.

@ronihcohen
Last active June 29, 2024 06:02
Show Gist options
  • Save ronihcohen/b4bb024ef90b393cc375afa03b5db734 to your computer and use it in GitHub Desktop.
Save ronihcohen/b4bb024ef90b393cc375afa03b5db734 to your computer and use it in GitHub Desktop.
Data from DS3231 displayed on 4 MAX7219
#include <MD_Parola.h>
#include <MD_MAX72xx.h>
#include <SPI.h>
#include <DS3231.h>
#define HARDWARE_TYPE MD_MAX72XX::FC16_HW
#define MAX_DEVICES 16
#define NUM_ZONES 4
#define CLK_PIN 13
#define DATA_PIN 11
#define CS_PIN 10
MD_Parola P = MD_Parola(HARDWARE_TYPE, CS_PIN, MAX_DEVICES);
DS3231 myRTC;
void setup() {
Serial.begin(57600);
P.begin(NUM_ZONES);
P.setIntensity(3);
// set the zone boundaries
P.setZone(0, 0, 3);
P.setZone(1, 4, 7);
P.setZone(2, 8, 11);
P.setZone(3, 12, 15);
}
char* getDow() {
const char* weekdays[] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
byte theWeekday = myRTC.getDoW();
return weekdays[theWeekday];
}
char* getDate() {
bool CenturyBit;
byte date = myRTC.getDate();
byte month = myRTC.getMonth(CenturyBit);
static char dateString[20];
sprintf(dateString, "%02d/%02d", date, month);
return dateString;
}
char* getTime() {
bool h12;
bool hPM;
byte hour = myRTC.getHour(h12, hPM);
byte min = myRTC.getMinute();
static char timeString[20];
sprintf(timeString, "%02d:%02d", hour, min);
return timeString;
}
char* getTemp() {
float rtcTemp = myRTC.getTemperature();
static char tempString[10]; // Enough space to hold the temperature as a string
// Convert float to string
dtostrf(rtcTemp, 2, 1, tempString); // 2 is minimum width, 1 is precision
sprintf(tempString, "%sc", tempString);
return tempString;
}
void loop() {
char* time = getTime();
char* temp = getTemp();
char* date = getDate();
char* dow = getDow();
if (P.displayAnimate())
P.displayZoneText(3, time, PA_LEFT, 0, 0, PA_NO_EFFECT, PA_NO_EFFECT);
P.displayZoneText(2, dow, PA_LEFT, 0, 0, PA_NO_EFFECT, PA_NO_EFFECT);
P.displayZoneText(1, date, PA_LEFT, 0, 0, PA_NO_EFFECT, PA_NO_EFFECT);
P.displayZoneText(0, temp, PA_LEFT, 0, 0, PA_NO_EFFECT, PA_NO_EFFECT);
delay(1000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment