#include <MD_Parola.h>
#include <MD_MAX72xx.h>
#include "Font_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_CLK_ZONES 2
#define ZONE_SIZE 8
#define MAX_DEVICES (MAX_CLK_ZONES * ZONE_SIZE)
#define ZONE_UPPER 1
#define ZONE_LOWER 0
//#define HARDWARE_TYPE MD_MAX72XX::PAROLA_HW
//#define MAX_DEVICES 8 // Define the number of displays connected
#define CLK_PIN 13 // CLK or SCK
#define DATA_PIN 11 // DATA or MOSI
#define CS_PIN 10 // CS or SS
#define SPEED_TIME 75 // Speed of the transition
#define PAUSE_TIME 0
#define MAX_MESG 20
// Hardware SPI connection
MD_Parola P = MD_Parola(HARDWARE_TYPE, CS_PIN, MAX_DEVICES);
// Hardware adaptation parameters for scrolling
bool invertUpperZone = false;
// ****** UTF8-Decoder: convert UTF8-string to extended ASCII *******
static byte c1; // Last character buffer
// Convert a single Character from UTF8 to Extended ASCII
// Return "0" if a byte has to be ignored
byte utf8ascii(byte ascii) {
if ( ascii<128 ) // Standard ASCII-set 0..0x7F handling
{ c1=0;
//Serial.println((unsigned int)ascii);
return( ascii );
}
// get previous input
byte last = c1; // get last char
c1=ascii; // remember actual character
switch (last) // conversion depending on first UTF8-character
{ case 0xE0:
return (ascii);
break;
case 0xB8:
// B8,81(129) ก - ฮ
if ((ascii+32)>=161 && (ascii+32)<=207) {
// ก 81 = 129 --> +32 --> 161
// Serial.println((unsigned int)ascii+32);
return (ascii);
}
// B8,B0(176) สระ
if ((ascii+32)>=208 && (ascii+32)<=218) {
// ะ B0 = 176 --> +32 --> 208
//Serial.println((unsigned int)ascii+32);
return (ascii);
}
break;
case 0xB9:
// B9,80(128) สระ
if ((ascii+96)>=224 && (ascii+96)<=231) {
// เ 80 = 176 --> +96 --> 224
//Serial.println((unsigned int)ascii+96);
return (ascii);
}
// B9,B0(136) วรรณยุก
if ((ascii+96)>=232 && (ascii+96)<=238) {
// ่ 88 = 136 --> +96 --> 208
//Serial.println((unsigned int)ascii+96);
return (ascii);
}
// B9,B0(240) ตัวเลขไทย ๑๒๓๔ู
if ((ascii+96)>=240 && (ascii+96)<=249) {
// ่ 88 = 142 --> +96 --> 240
//Serial.println((unsigned int)ascii+96);
return (ascii);
}
break;
case 0x82:
if(ascii==0xAC)
return(0x80); // special case Euro-symbol
}
return (0); // otherwise: return zero, if character has to be ignored
}
// convert String object from UTF8 String to Extended ASCII
String utf8ascii(String s)
{
String r="";
char c;
for (int i=0; i<s.length(); i++)
{
c = utf8ascii(s.charAt(i));
if (c!=0) r+=c;
}
return r;
}
// In Place conversion UTF8-string to Extended ASCII (ASCII is shorter!)
void utf8ascii(char* s)
{
int k=0;
char c;
for (int i=0; i<strlen(s); i++)
{
Serial.println((unsigned char)s[i]);
c = utf8ascii(s[i]);
if (c!=0)
s[k++]=c;
}
s[k]=0;
}
void setup() {
// put your setup code here, to run once:
Serial.begin(57600);
invertUpperZone = (HARDWARE_TYPE == MD_MAX72XX::GENERIC_HW || HARDWARE_TYPE == MD_MAX72XX::PAROLA_HW);
// initialise the LED display
P.begin(MAX_CLK_ZONES);
// Set up zones for 2 halves of the display
P.setZone(ZONE_LOWER, 0, ZONE_SIZE - 1);
P.setZone(ZONE_UPPER, ZONE_SIZE, MAX_DEVICES - 1);
P.setFont(ThaiFont);
char* s="เ";//s="๐๑๒๓๔๕๖๗๘๙";
Serial.println("UTF8-decoder Test");
Serial.print("Original: ");
Serial.println(s);
utf8ascii(s);
//Serial.print("Extended ASCII-Version ");
}
void loop() {
// put your main code here, to run repeatedly:
}