// this module interacts with the hardware on lower level
#include <MD_MAX72xx.h>
#include <stdio.h>
#include <string.h>
#include <MD_Parola.h>
#include <SPI.h>
const byte clock_pin = 13;
const byte data_pin = 11;
const byte chip_select_pin = 10;
const byte max_devices = 8;
#include <Wire.h>
#include <RTClib.h>
RTC_DS3231 rtc; // Create an RTC object
DateTime now(2024, 12, 3, 10, 26, 0);
String y;
String m;
String d;
int h;
int hours;
String mnt;
int minutes;
String s;
int i=0;
float temp;
String TimeStamp = "";
MD_Parola matrix = MD_Parola(MD_MAX72XX::PAROLA_HW, chip_select_pin, max_devices);
void setup(){
Serial.begin(115200);
Serial.println("hi");
if (!rtc.begin()) {
Serial.println("Couldn't find RTC");
while (1);
}
if (rtc.lostPower()) {
Serial.println("RTC lost power, setting the time!");
// Set the RTC to the date & time this sketch was compiled
//rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
// Set the RTC to the manual date & time defined above
rtc.adjust(now);
} else {
//rtc.adjust(now);
Serial.println("RTC is running with correct time.");
}
matrix.begin(); // initialise the module
matrix.displayClear(); // clear, if there is anything
matrix.displayText("intro scroll", PA_CENTER, 20, 4,PA_SCROLL_LEFT , PA_SCROLL_LEFT );
}
void loop(){
matrix.displayClear();
while(1) {
char buffer[40];
//Serial.print("waiting");
if (matrix.displayAnimate()){
DateTime now = rtc.now();
y = now.year();
m = now.month();
d = now.day();
h = now.hour();
hours = now.hour();
Serial.println(h);
Serial.println(hours);
Serial.println(sizeof(h));
mnt = now.minute();
minutes = now.minute();
s = now.second();
if(i>9){i=0;}
i++;
char buffer[40];
strcpy(buffer, "");
Serial.println("initial buffer");
Serial.println(buffer);
String hstr = String(h);
Serial.println(h);
const char* hr = hstr.c_str();
Serial.println(hr);
//strcat(buffer, ">----- ");
strcat(buffer, hr);
Serial.println(buffer);
strcat(buffer, ":");
Serial.print(buffer);
if(minutes<10){strcat(buffer, "0");}
const char* minute = mnt.c_str();
strcat(buffer, minute);
strcat(buffer, " Temp: ");
Serial.println("");
Serial.println(buffer);
temp = (rtc.getTemperature())*9/5+32;
String tempstr = String(temp, 2);
const char* tempconstchar = tempstr.c_str();
strcat(buffer, tempconstchar);
strcat(buffer, " F ");
Serial.println(temp);
Serial.println("");
//strcat(buffer, " -----< ");
matrix.displayText(buffer, PA_CENTER, 30, 2,PA_SCROLL_LEFT, PA_SCROLL_LEFT);
matrix.displayClear();
}
Serial.println("scroll not finished");
}
}