/*we used Serial.readStringUntil() insted of Serial.readBytesUntil() because we are dealing with a
string and we are going to count the characters in the string.*/
//libraries
#include <MD_Parola.h>
#include <MD_MAX72xx.h>
#include <SPI.h>
//definitions
#define HARDWARE_TYPE MD_MAX72XX::PAROLA_HW
#define devices 4
#define clk 13
#define data 11
#define CS 10
MD_Parola play = MD_Parola(HARDWARE_TYPE, data, clk, CS, devices);
//methods
//a method used to count the number of characters
int numbers_of_characters(String s){
int count = 0;
while(s[count] != NULL){
count++;
}
return count;
}
//taking the string and breaking it to its characters
char* returning_characters(String x){
int count = numbers_of_characters(x);
char* y = malloc(count);
strcpy(y, x.c_str());
return y;
}
//to keep displayig the message
void displaying(){
while(1){
if(Serial.available() > 0){
break;
}
else {
if(play.displayAnimate()){
play.displayReset();
}
}
}
}
void setup(void)
{
Serial.begin(9600);//the serial communication
//initiating the message
Serial.println(F("Enter a message: "));
Serial.println(F("- REMEMBER: max. of 20 characters only -"));
//initiate the displaying process
play.begin();
}
void loop(void)
{
if(Serial.available() > 0){//if there is any message in the serial port, then true = more than a zero
String msg = Serial.readStringUntil('\n');/*read what's written until there is a new line.*/
int x = numbers_of_characters(msg);
if(x >= 20){
Serial.println(F("Your message size exceeds the limit."));
}
else {
Serial.print(F("Your message: "));
Serial.println(msg);
char* message = returning_characters(msg);
play.displayText(message, PA_CENTER, 100, 0, PA_SCROLL_LEFT, PA_SCROLL_LEFT);
}
}
displaying();
}