#include <MD_Parola.h>
#include <MD_MAX72xx.h>
#include <string.h>
#define HARDWARE_TYPE MD_MAX72XX::PAROLA_HW
#define MAX_DEVICES 1
#define CLK_PIN 13
#define DATA_PIN 11
#define CS_PIN 10
uint8_t scrollSpeed = 50; // default frame delay value
textEffect_t scrollEffect = PA_SCROLL_LEFT;
textPosition_t scrollAlign = PA_LEFT;
uint16_t scrollPause = 2000; // in milliseconds
MD_Parola P = MD_Parola(HARDWARE_TYPE, CS_PIN, MAX_DEVICES);
MD_MAX72XX mx = MD_MAX72XX(HARDWARE_TYPE, CS_PIN, MAX_DEVICES);
#define BUF_SIZE 26
char curMessage[BUF_SIZE] = { "" };
char newMessage[BUF_SIZE] = { "Hello world" };
bool newMessageAvailable = true;
// symbols
const byte CROSS[8] = {
0b10000001,
0b01000010,
0b00100100,
0b00011000,
0b00011000,
0b00100100,
0b01000010,
0b10000001
};
const byte CIRCLE[8] = {
0b00011000,
0b01100110,
0b01000010,
0b10000001,
0b10000001,
0b01000010,
0b01100110,
0b00011000
};
const byte CHECKMARK[8] = {
0b00000000,
0b00000001,
0b00000010,
0b00000100,
0b10001000,
0b01010000,
0b00100000,
0b00000000
};
// pareizo ievadu varianti salīdzināšanai/ievada pārbaudei vēlāk
char okCheck[] = "cOK";
char nopeCheck[] = "cNOPE";
bool showText = false;
void displayAction() {
readSerial();
if (P.displayAnimate())
{
if (newMessageAvailable)
{
strcpy(curMessage, newMessage);
newMessageAvailable = false;
}
P.displayReset();
}
}
// Pirmā funkcija izvada tekstu "scrollojot" to no pirmā līdz pēdējam simbolam
void displayMessage() {
for (char *ps = newMessage; *ps != '\0'; ps++)
*ps = *(ps + 1);
Serial.println(newMessage);
newMessageAvailable = true;
}
// Otrā funkcija izvada vienu simbolu, atkarībā no saņemtā teksta
byte displaySymbols(byte symbol[8]) {
mx.clear();
for (int i = 0; i < 8; i++) {
mx.setRow(0, i, symbol[i]);
}
delay(2000);
mx.clear();
return;
}
void validateInput() {
if (strncmp(newMessage, okCheck, BUF_SIZE) == 0)
{
displaySymbols(CHECKMARK);
}
else if (strncmp(newMessage, nopeCheck, BUF_SIZE) == 0)
{
displaySymbols(CROSS);
}
else
{
displaySymbols(CIRCLE);
}
}
void readSerial(void)
{
static char *cp = newMessage;
while (Serial.available())
{
*cp = (char)Serial.read();
if ((*cp == '\n') || (cp - newMessage >= BUF_SIZE)) // end of message character or full buffer
{
*cp = '\0'; // end the string
// restart the index for next filling spree and flag we have a message waiting
cp = newMessage;
if (newMessage[0] == 's')
{
displayMessage();
}
else if (newMessage[0] == 'c')
{
validateInput();
}
else {
Serial.println("Nav tādas komandas (Ievadam jāsākās ar \"s\" vai \"c\")");
}
}
else // move char pointer to next position
cp++;
}
}
void setup() {
Serial.begin(57600);
Serial.print("\n[Parola Scrolling Display]\nIevadiet līdz 25 zīmēm\n");
mx.begin();
P.begin();
P.displayText(curMessage, scrollAlign, scrollSpeed, scrollPause, scrollEffect, scrollEffect);
}
void loop() {
displayAction();
}