// Program to exercise the MD_Parola library
//
// Display text using various fonts.
//
// MD_MAX72XX library can be found at https://github.com/MajicDesigns/MD_MAX72XX
//
#include <MD_Parola.h>
#include <MD_MAX72xx.h>
#include <SPI.h>
#include "ArduinoTrace.h"
#include "Parola_Fonts_data.h"
// Define the number of devices we have in the chain and the hardware interface
// 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 11
#define CLK_PIN 13
#define DATA_PIN 11
#define CS_PIN 10
// HARDWARE SPI
MD_Parola P = MD_Parola(HARDWARE_TYPE, CS_PIN, MAX_DEVICES);
// SOFTWARE SPI
//MD_Parola P = MD_Parola(HARDWARE_TYPE, DATA_PIN, CLK_PIN, CS_PIN, MAX_DEVICES);
#define PAUSE_TIME 3000
// Turn on debug statements to the serial output
#define DEBUG 0
// #if DEBUG
// #define PRINT(s, x) { Serial.print(F(s)); Serial.print(x); }
// #define PRINTS(x) Serial.print(F(x))
// #define PRINTX(s, x) { Serial.print(F(s)); Serial.print(x, HEX); }
// #else
// #define PRINT(s, x)
// #define PRINTS(x)
// #define PRINTX(s, x)
// #endif
char buf[20]="HOLB";
String pMsg,qs;
// Global variables
// typedef struct
// {
// char name[10];
// MD_MAX72XX::fontType_t *pFont;
// textEffect_t effect;
// char *pMsg;
// } message_t;
// const message_t M[] =
// {
// //{ "Roman", nullptr, PA_SCROLL_LEFT, "Arduinó" },
// //{ "", fontComplete, PA_SCROLL_LEFT, "Arduin\x0f3" },
// { "", fontComplete, PA_SCROLL_LEFT, "Arduónó" },
// { "Japanese", fontKatakana, PA_SCROLL_LEFT, "\x0b1\x0b0\x0c2\x0b2\x0c9" },
// { "Arabic", fontArabic, PA_SCROLL_RIGHT, "\x0a9\x0a7\x0ab\x0a9\x090\x0a5\x088" }, // ا ر د و ي ن و
// { "Greek", fontGreek, PA_SCROLL_LEFT, "\x080\x0a8\x09b\x0b2\x0a0\x0a4\x0a6" }
// };
// uint8_t curM = 0; // current message definition to use
// char q='\x00f3';
int j=0;
void setup(void)
{
char chrSaved;
Serial.begin(57600);
//PRINTS("\n[Parola Demo]");
//Serial.println(q);
//pMsg="óRáéíóúÑñÜü";
//pMsg="Electrónica";
//pMsg="Año Nuevo";
pMsg="AÑO NUEVO";
DUMP(pMsg.length()); //the length of a string
DUMP(sizeof pMsg); //the size of the variable
//DUMP(M[curM].pMsg[j]);
DUMP((uint8_t)pMsg[j]); //ó : c3 : Ã en Parola default fonts
DUMP((uint8_t)pMsg[j+1]); // : b3 : ³ en Parola default fonts
DUMP(j);
DUMP((pMsg));
//BREAK();
// for(j=0;j<20;j++)
// {
// DUMP(j);
// DUMP(pMsg[j]);
// }
//https://www.fileformat.info/info/charset/UTF-8/list.htm
//á : c3a1 : 195 161
//é : c3a9 : 195 169
//í : c3ad : 195 173
//ó : c3b3 : 195 179
//ú : c3ba : 195 186
//Ñ : c391
//ñ : c3b1
//Ü : c39c
//ü : c3bc
for(j=0;j<20;j++)
{
if(pMsg[j]=='\xC3'&&pMsg[j+1]=='\xA1' ) //á
{
DUMP(j);
pMsg[j]='\xE1';
DUMP(pMsg[j+1]);
for(int k=j;k<20;k++)
{
pMsg[k+1]=pMsg[k+2];
}
}
}
for(j=0;j<20;j++)
{
if(pMsg[j]=='\xC3'&&pMsg[j+1]=='\xA9' ) //é
{
DUMP(j);
pMsg[j]='\xE9';
DUMP(pMsg[j+1]);
for(int k=j;k<20;k++)
{
pMsg[k+1]=pMsg[k+2];
}
}
}
for(j=0;j<20;j++)
{
if(pMsg[j]=='\xC3'&&pMsg[j+1]=='\xAD' ) //í
{
DUMP(j);
pMsg[j]='\xED';
DUMP(pMsg[j+1]);
for(int k=j;k<20;k++)
{
pMsg[k+1]=pMsg[k+2];
}
}
}
for(j=0;j<20;j++)
{
if(pMsg[j]=='\xC3'&&pMsg[j+1]=='\xb3' ) //ó
{
DUMP(j);
pMsg[j]='\xF3';
DUMP(pMsg[j+1]);
for(int k=j;k<20;k++)
{
pMsg[k+1]=pMsg[k+2];
}
}
}
for(j=0;j<20;j++)
{
if(pMsg[j]=='\xC3'&&pMsg[j+1]=='\xBA' ) //ú
{
DUMP(j);
pMsg[j]='\xFA';
DUMP(pMsg[j+1]);
for(int k=j;k<20;k++)
{
pMsg[k+1]=pMsg[k+2];
}
}
}
for(j=0;j<20;j++)
{
if(pMsg[j]=='\xC3'&&pMsg[j+1]=='\x91' ) //Ñ
{
DUMP(j);
pMsg[j]='\xD1';
DUMP(pMsg[j+1]);
for(int k=j;k<20;k++)
{
pMsg[k+1]=pMsg[k+2];
}
}
}
for(j=0;j<20;j++)
{
if(pMsg[j]=='\xC3'&&pMsg[j+1]=='\xB1' ) //ñ
{
DUMP(j);
pMsg[j]='\xF1';
DUMP(pMsg[j+1]);
for(int k=j;k<20;k++)
{
pMsg[k+1]=pMsg[k+2];
}
}
}
for(j=0;j<20;j++)
{
if(pMsg[j]=='\xC3'&&pMsg[j+1]=='\x9C' ) //Ü
{
DUMP(j);
pMsg[j]='\xDC';
DUMP(pMsg[j+1]);
for(int k=j;k<20;k++)
{
pMsg[k+1]=pMsg[k+2];
}
}
}
for(j=0;j<20;j++)
{
if(pMsg[j]=='\xC3'&&pMsg[j+1]=='\xBC' ) //ü
{
DUMP(j);
pMsg[j]='\xFC';
DUMP(pMsg[j+1]);
for(int k=j;k<20;k++)
{
pMsg[k+1]=pMsg[k+2];
}
}
}
DUMP(pMsg);
pMsg.toCharArray(buf, 20); //pasing String (pMsg) to char array (buf) OK
DUMP(strlen(buf)); //String length:numero de bytes en "óRó" = 3 (despues del proceso que hicimos)
DUMP(sizeof(buf)); //Array length = 20
// qs=buf; //paso de buf (char array) to string OK
// DUMP(qs);
// int i=0,k;
// while((M[curM].pMsg[i])!='\0')
// {
// if((M[curM].pMsg[i])=='\x00c3')
// {
// DUMP("HOLA");
// chrSaved=M[curM].pMsg[i+2];
// DUMP(M[curM].pMsg[i]);
// M[curM].pMsg[i]=q;
// DUMP(M[curM].pMsg[i]);
// M[curM].pMsg[i+1]= chrSaved;
// // for(k=i+2;k<10;k++)
// // {
// // M[curM].pMsg[k+2]=M[curM].pMsg[k+3];
// // }
// //BREAK();
// }
// M[curM].pMsg[7]=0;
// DUMP((byte)M[curM].pMsg[7]);
// DUMP(M[curM].pMsg);
// //BREAK();
// i++;
// }
//DUMP('\x00f3');
//BREAK();
//curM=0;
P.begin();
P.setFont(fontComplete);
//P.displayText(buf, PA_CENTER, P.getSpeed(), PAUSE_TIME, PA_SCROLL_LEFT, PA_SCROLL_LEFT);
// BREAK();
}
void loop(void)
{
//curM=0;
if (P.displayAnimate())
{
//P.displayText(buf, PA_CENTER, P.getSpeed(), PAUSE_TIME, PA_SCROLL_LEFT, PA_SCROLL_LEFT);
P.displayText(buf, PA_CENTER, P.getSpeed(), PAUSE_TIME, PA_PRINT, NULL);
//curM = (curM + 1) % ARRAY_SIZE(M);
// PRINT("\nChanging font to ", M[curM].name);
// PRINTS(", msg data ");
// for (uint8_t i = 0; i<strlen(M[curM].pMsg); i++)
// {
// PRINTX(" 0x", (uint8_t)M[curM].pMsg[i]);
// }
//P.setFont(fontComplete);
//P.setTextBuffer(M[curM].pMsg);
//P.setTextEffect(M[curM].effect, M[curM].effect);
// P.displayText(M[curM].pMsg, PA_CENTER, P.getSpeed(), PAUSE_TIME, PA_SCROLL_LEFT, PA_SCROLL_LEFT);
//P.displayReset();
}
}