// Use the Parola library to scroll text on the display
//
// Demonstrates the use of the scrolling function to display text received
// from the serial interface
//
// User can enter text on the serial monitor and this will display as a
// scrolling message on the display.
// Speed for the display is controlled by a pot on SPEED_IN analog in.
// Scrolling direction is controlled by a switch on DIRECTION_SET digital in.
// Invert ON/OFF is set by a switch on INVERT_SET digital in.
//
// UISwitch library can be found at https://github.com/MajicDesigns/MD_UISwitch
// MD_MAX72XX library can be found at https://github.com/MajicDesigns/MD_MAX72XX
//
#include <SoftwareSerial.h>
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::PAROLA_HW//Used for simulation only
//#define HARDWARE_TYPE MD_MAX72XX::FC16_HW
#define MAX_DEVICES 12
#define NUM_ZONES 5
#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_CENTER },//Looks nicer centred up
{ 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 },
};
int zSwitch = 0; // switch to 1 when bluetooth data received
int P1Total = 0; // Stores Player 1 Total Games Won
int P2Total = 0; // Stores Player 2 Total Games Won
char BT1Str[4] = {0};
char BT2Str[4] = {0};
char total1Str[4] = {0};
char total2Str[4] = {0};
uint8_t i = 0;
bool stop = false;
void intro () {
Serial.print("intro ");
Serial.println(i);
P.displayZoneText(4, animList[i].textOut, animList[i].just, animList[i].speed,
animList[i].pause, animList[i].anim_in, animList[i].anim_out);
}
void setup() {
Serial.begin(115200);
//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.setZone(4, 0, 11);
P.setIntensity(2);
Serial.println("Go Go Go");// Activates the sim Serial monitor
for (uint8_t i = 0; i < ARRAY_SIZE(animList); i++) {
animList[i].speed *= P.getSpeed();
animList[i].pause *= 500;
}
intro ();
}
void loop() {
byte n = Serial.available();
//byte n = SUART.available();
if (n != 0 && stop) {
//zSwitch = zSwitch + 1;
char ch = Serial.read();
//char ch = SUART.read();
if (ch == '<') //start mark found
{
byte m = Serial.readBytesUntil('>', myData, sizeof myData - 1);
//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); // Player 1 Score
//-------------------------
token = strtok(NULL, ",");
int BTScore2 = atoi(token);
Serial.println(BTScore2); // Player 2 Score
//-------------------------
if (BTScore1 == 0 ) {
P.displayClear(3);
P.displayZoneText(3, "-PEG-", PA_CENTER, 0, 0, PA_PRINT, PA_NO_EFFECT);
} else if (BTScore2 == 0) {
P.displayClear(0);
P.displayZoneText(0, "-PEG-", PA_CENTER, 0, 0, PA_PRINT, PA_NO_EFFECT);
}
else {
itoa(BTScore1, BT1Str, 10);
itoa(BTScore2, BT2Str, 10);
P.displayZoneText(0, BT2Str, PA_CENTER, 0, 0, PA_PRINT, PA_NO_EFFECT);
P.displayZoneText(3, BT1Str, PA_CENTER, 0, 0, PA_PRINT, PA_NO_EFFECT);
}
//------------------------- //-------------------------<A,C,212,300>
if (BTLed1 == 'A') {
P.displayClear(1);
P.displayZoneText(2, "<-", PA_CENTER, 0, 0, PA_PRINT, PA_NO_EFFECT);
}
if (BTLed2 == 'C') {
P.displayClear(2);
P.displayZoneText(1, "->", PA_CENTER, 0, 0, PA_PRINT, PA_NO_EFFECT);
}
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) {
itoa (P1Total, total1Str, 10);
itoa (P2Total, total2Str, 10);
P.displayZoneText(1, total2Str, PA_CENTER, 0, 0, PA_PRINT, PA_NO_EFFECT);
P.displayZoneText(2, total1Str, PA_CENTER, 0, 0, PA_PRINT, PA_NO_EFFECT);
}
}
} // xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
if (P.displayAnimate()) {
if (P.getZoneStatus(4)){
i++;
if(Serial.available()) Serial.println("Scores In");
if(i == 4) i = 0;
if(!stop) {
if (i == 0 && Serial.available()) {
P.displayClear(4);
stop = true;
} else {
delay(1000);
intro();
}
}
}
P.displayReset();
}
}