OK here is my code (and it works fine) however at the very end of my code is "if (token == 0)" .
I want to run scrolling text (a list of animations) across all 4 zones if the "if" is true.
SoftwareSerial SUART(9, 5); //SRX = 10, STX = 11
char myData[20];
char *token;
#include <MD_Parola.h>
#include <MD_MAX72xx.h>
#include <SPI.h>
#define HARDWARE_TYPE MD_MAX72XX::FC16_HW
#define MAX_DEVICES 12
#define NUM_ZONES 4
#define CLK_PIN 13
#define DATA_PIN 11
#define CS_PIN 10
MD_Parola P = MD_Parola(HARDWARE_TYPE, CS_PIN, MAX_DEVICES);
int P1Total = 0; // Stores Player 1 Total Games Won
int P2Total = 0; // Stores Player 2 Total Games Won
void setup() {
Serial.begin(9600);
SUART.begin(38400); //38400 for scoreboard "Slave 4"
P.begin(NUM_ZONES);
P.setZone(0, 0, 3);
P.setZone(1, 4, 5);
P.setZone(2, 6, 7);
P.setZone(3, 8, 11);
P.setIntensity(2);
}
void loop() {
byte n = SUART.available();
if (n != 0) {
char ch = SUART.read();
if (ch == '<') //start mark found
{
byte m = SUART.readBytesUntil('>', myData, sizeof myData - 1);
myData[m] = '\0'; //null-charcater
Serial.println(myData);
//--------------------------
token = strtok(myData, ",");
char BTLed1 = *token;
Serial.println(BTLed1); // LED1
//-------------------------
token = strtok(NULL, ",");
char BTLed2 = *token;
Serial.println(token); // LED2
//-------------------------
token = strtok(NULL, ",");
int BTScore1 = atoi(token);
Serial.println(BTScore1, DEC); // Player 1 Score
//-------------------------
token = strtok(NULL, ",");
int BTScore2 = atoi(token);
Serial.println(BTScore2, DEC); // Player 2 Score
//-------------------------
if (BTScore1 == 0) {
P.displayClear(3);
P.displayZoneText(3, ("-PEG-"), PA_CENTER, 0, 0, PA_PRINT, PA_NO_EFFECT);
P.displayAnimate();
} else if (BTScore2 == 0) {
P.displayClear(0);
P.displayZoneText(0, ("-PEG-"), PA_CENTER, 0, 0, PA_PRINT, PA_NO_EFFECT);
P.displayAnimate();
}
else {
String score1Str = String(BTScore1);
String score2Str = String(BTScore2);
P.displayZoneText(0, score2Str.c_str(), PA_CENTER, 0, 0, PA_PRINT, PA_NO_EFFECT);
P.displayZoneText(3, score1Str.c_str(), PA_CENTER, 0, 0, PA_PRINT, PA_NO_EFFECT);
P.displayAnimate();
}
//-------------------------
if (BTLed1 == 'A') {
P.displayClear(1);
P.displayZoneText(2, ("<-"), PA_CENTER, 0, 0, PA_PRINT, PA_NO_EFFECT);
P.displayAnimate();
}
if (BTLed2 == 'C') {
P.displayClear(2);
P.displayZoneText(1, ("->"), PA_CENTER, 0, 0, PA_PRINT, PA_NO_EFFECT);
P.displayAnimate();
}
if (BTScore1 == 0) P1Total = P1Total + 1;
{
Serial.println(P1Total, DEC);
}
if (BTScore2 == 0) P2Total = P2Total + 1;
{
Serial.println(P2Total, DEC);
}
if (BTScore1 == 0 || BTScore2 == 0) {
P.displayClear(1);
P.displayClear(2);
String total1Str = String(P1Total);
String total2Str = String(P2Total);
P.displayZoneText(1, total2Str.c_str(), PA_CENTER, 0, 0, PA_PRINT, PA_NO_EFFECT);
P.displayZoneText(2, total1Str.c_str(), PA_CENTER, 0, 0, PA_PRINT, PA_NO_EFFECT);
P.displayAnimate();
}
}
}
if (token == 0) {
P.displayZoneText(0, ("--=={}"), PA_CENTER, 0, 0, PA_PRINT, PA_NO_EFFECT);
P.displayZoneText(1, ("={}"), PA_CENTER, 0, 0, PA_PRINT, PA_NO_EFFECT);
P.displayZoneText(2, ("--="), PA_RIGHT, 0, 0, PA_PRINT, PA_NO_EFFECT);
P.displayZoneText(3, ("--=={}"), PA_CENTER, 0, 0, PA_PRINT, PA_NO_EFFECT);
P.displayAnimate();
}
}
I also have this code that works on its own but i cant get them to work together .
#include <MD_Parola.h>
#include <MD_MAX72xx.h>
#define HARDWARE_TYPE MD_MAX72XX::FC16_HW
#define MAX_DEVICES 12
#define CLK_PIN 13
#define DATA_PIN 11
#define CS_PIN 10
MD_Parola P = MD_Parola(HARDWARE_TYPE, CS_PIN, MAX_DEVICES);
struct animations {
textEffect_t anim_in; // Animation type
textEffect_t anim_out; // Animation type
const char* textOut; // Text to display
uint16_t speed; // Animation speed (multiplier for library default)
uint16_t pause; // pause (multiplier for library default)
textPosition_t just;
};
animations animList[] = {
{ PA_SCROLL_LEFT, PA_SCROLL_UP_RIGHT, "--=={} --=={} --=={}", 1, 6, PA_LEFT },
{ PA_RANDOM, PA_RANDOM, "Glen's Darts Comp ", 1, 8, PA_LEFT },
{ PA_SCROLL_LEFT, PA_SCROLL_UP_RIGHT, "--=={} --=={} --=={}", 1, 6, PA_LEFT },
{ PA_SCROLL_LEFT, PA_SCROLL_LEFT, "Lets throw some Darts!", 2, 0, PA_LEFT },
};
void setup() {
P.begin();
for (uint8_t i = 0; i < ARRAY_SIZE(animList); i++) {
animList[i].speed *= P.getSpeed();
animList[i].pause *= 500;
}
}
void loop() {
static uint8_t i = 0; // text effect index
if (P.displayAnimate()) // animates and returns true when an animation is completed
{
if (i == ARRAY_SIZE(animList)) i = 0; // reset loop index
P.displayText(animList[i].textOut, animList[i].just, animList[i].speed,
animList[i].pause, animList[i].anim_in, animList[i].anim_out);
delay(1000);
i++; // then set up for next text effect
}
}