Hi everyone,
I am building ESP2866 Parola WiFi LED matrix clock. I know almost nothing about programming and so I am just modifying another project that works with DS3231 RTC.
So far I got time and date and day of week displaying correctly.
Now I want to add code to display something like "Today is John's birthday" at the corresponding date. So I created another char * array, containing all family members names. But it does not work - instead of displaying any name from that array, it displays some strange characters. And I don´t know how to correct it. I have read various examples about arrays, but dont understand it well.
Here is my code:
/*Arduino Clock by AnthoTRONICS
* Last edit: March 22,2019
*/
// Libraries you'll need (Same as the ones in the guide:
// TAKE NOTE OF THE VERSIONS!!!
// MD Parola 3.3.0: https://github.com/MajicDesigns/MD_Parola // click the link to download the library
// MD_MAX72XX 3.2.1: https://github.com/MajicDesigns/MD_MAX72XX //click the link to download the library
// not using DS3231 1.0.2: https://github.com/NorthernWidget/DS3231 // click the link to download
// NTPClient 3.1.0
/*CODE:*/
// Header file includes
// These are for the matrix
#include <MD_Parola.h>
#include <MD_MAX72xx.h>
#include <SPI.h>
#include "Font_Data.h"
//These are for the clock
#include <NTPClient.h>
#include <ESP8266WiFi.h>
#include <WiFiUdp.h>
const char *ssid = "Jeho_WIFI";
const char *password = "DyKCcrg_rdrigVX2WO2G";
WiFiUDP ntpUDP;
NTPClient timeClient(ntpUDP, "europe.pool.ntp.org", 7200, 60000);
#include <Wire.h>
// NOTE: These pin numbers will probably not work with your hardware and may
// need to be adapted
#define HARDWARE_TYPE MD_MAX72XX::PAROLA_HW
#define MAX_DEVICES 5
#define CLK_PIN D5
#define DATA_PIN D7
#define CS_PIN D8
// Hardware SPI connection
MD_Parola P = MD_Parola(HARDWARE_TYPE,CS_PIN, MAX_DEVICES);
#define SPEED_TIME 50 // speed of the transition
#define PAUSE_TIME 0
#define MAX_MESG 20
// Global variables
char szTime[9]; // mm:ss\0
char szMesg[MAX_MESG+1] = "";
bool Century=false;
bool h12;
bool PM;
byte dd,mm,yyy;
uint16_t h, m, s;
char rok;
char mesiac;
char den;
char aky_sviatok ;
char kto_sviatok ;
// This part works fine - prepares name of month for displaying later
char *mon2str(uint8_t mon, char *psz, uint8_t len)
// Get a label from PROGMEM into a char array
{
static const __FlashStringHelper* str[] =
{
F("Januar"), F("Februar"), F("Marec"), F("April"),
F("Maj"), F("Jun"), F("Jul"), F("August"),
F("September"), F("Oktober"), F("November"), F("December")
};
strncpy_P(psz, (const char PROGMEM *)str[mon-1], len);
psz[len] = '\0';
return(psz);
}
//This part works fine - prepares name of day (monday - sunday) for displaying later
char *dow2str(uint8_t code, char *psz, uint8_t len)
{
static const __FlashStringHelper* str[] =
{
F("Nedela"), F("Pondelok"),
F("Utorok"), F("Streda"), F("Stvrtok"),
F("Piatok"), F("Sobota"),
};
strncpy_P(psz, (const char PROGMEM *)str[code-1], len);
psz[len] = '\0';
return(psz);
}
void getDays(char *psz)
{
char szBuf[10];
dd = timeClient.getFormattedDate().substring( 8, 10).toInt();
mm = timeClient.getFormattedDate().substring( 6, 7).toInt();
yyy = timeClient.getFormattedDate().substring( 2, 4).toInt();
sprintf(psz, "%s",dow2str(timeClient.getDay()+1, szBuf, sizeof(szBuf)-1));
}
//This is problematic part
//Family members names
char *Names(uint8_t code, char *psz, uint8_t len)
{
static const __FlashStringHelper* str[] =
{
F("babka"), F("dedko"),
F("Marcela"), F("Dita"), F("Lukas"), F("Pepa"), F("Ina"),
F("Martin"), F("Martin_jr."),
F("Martina"), F("Ela"), F("Domino"), F("Juraj"),
};
strncpy_P(psz, (const char PROGMEM *)str[code-1], len);
psz[len] = '\0';
return(psz);
}
void getName(char *psz)
{
char szBuf[15];
sprintf(psz, "%s",Names[2], szBuf, sizeof(szBuf)-1);
}
//This works fine - prepares time in HH:MM format for displaying later
void getTime(char *psz, bool f = true)
{
s = timeClient.getSeconds();
m = timeClient.getMinutes();
h = timeClient.getHours(); //24hr Format
sprintf(psz, "%02d%c%02d", h, (f ? ':' : ' '), m);
}
// This works fine - prepares date and year like 18 Maj 2020
void getDate(char *psz)
{
char szBuf[10];
dd = timeClient.getFormattedDate().substring( 8, 10).toInt();
mm = timeClient.getFormattedDate().substring( 6, 7).toInt();
yyy = timeClient.getFormattedDate().substring( 2, 4).toInt();
sprintf(psz, "%02d %s %04d",dd , mon2str(mm, szBuf, sizeof(szBuf)-1),(yyy+2000));
}
//This works fine - prepares date in DD.MM. format like 18.05.
void getDate_2(char *psz)
{
char szBuf[10];
sprintf(psz, "%02d%c%02d%c",dd ,'.', mm , '.');
}
void setup(void)
{
Serial.begin(9600);
WiFi.begin(ssid, password);
while ( WiFi.status() != WL_CONNECTED ) {
delay ( 500 );
Serial.print ( "." );
}
timeClient.begin();
P.begin(0);
P.setInvert(false); //we don't want to invert anything so it is set to false
P.setZone(0, MAX_DEVICES-5, MAX_DEVICES-1);
P.setZone(1, MAX_DEVICES-5, MAX_DEVICES-1);
P.setIntensity(15);
P.displayZoneText(1, szTime, PA_CENTER, SPEED_TIME, PAUSE_TIME, PA_PRINT, PA_NO_EFFECT);
P.displayZoneText(0, szMesg, PA_CENTER, SPEED_TIME, PAUSE_TIME,PA_PRINT , PA_NO_EFFECT);
}
void loop(void)
{
timeClient.update();
static uint32_t lastTime = 0; // millis() memory
static uint8_t display = 0; // current display mode
static bool flasher = false; // seconds passing flasher
P.displayAnimate();
if (P.getZoneStatus(0))
{
switch (display)
{
case 0: // This works fine - displaying day of week Monday - Sunday
P.setPause(0,3000);
P.setTextEffect(0, PA_OPENING_CURSOR, PA_SCROLL_DOWN);
display++;
getDays(szMesg);
break;
case 1: // This works fine - displaying date in DD.MM format like 18.05.
P.setPause(0,3000);
P.setTextEffect(0, PA_MESH, PA_GROW_DOWN);
display++;
getDate_2(szMesg);
break;
case 2: // This works fine - displaying time in HH:MM format like 13:55
P.setFont(0, numeric7Seg);
P.setTextEffect(0, PA_PRINT, PA_NO_EFFECT);
P.setPause(0,0);
if (millis() - lastTime >= 1000)
{
lastTime = millis();
getTime(szMesg, flasher);
flasher = !flasher;
}
if(s==15&& s<=45)
{
display++;
P.setTextEffect(0, PA_PRINT, PA_SCROLL_LEFT);
}
break;
case 3: // This is ok - scrolls day of week like Monday
P.setFont(0,nullptr);
P.setTextEffect(0, PA_SCROLL_LEFT, PA_SCROLL_LEFT);
display++;
getDays(szMesg);
break;
case 4: // This is ok - scrolls date and year like 18 May 2020
P.setTextEffect(0, PA_SCROLL_LEFT, PA_SCROLL_LEFT);
display++;
getDate(szMesg);
break;
case 5: // This is problematic - it should scroll one name of family member
//but it scrolls strange characters
P.setTextEffect(0, PA_SCROLL_LEFT, PA_SCROLL_LEFT);
display = 0;
getName(szMesg);
break;
}
P.displayReset(0);
}
} //END of code
Can anybody help me with that, please?