Hi, I'm totally newby with arduino. I'm trying to create a marquee for a person who has Alzheimer. The Idea is that his daughter should be able to activate a marquee which is controlled with a dashboard. The main problem that I have is that sometimes the state of the arduino side and the dashboard are out of sync. The dashboard only have a switch to turn on the marquee and a led to know if the marquee are running. But if I activate the marque using the mobile app sometime when reload the app the switch appear off while the arduino marquee is running, so it's impossible to know the real state of the arduino side. The code:
#include "arduino_secrets.h"
// Adafruit NeoMatrix - Version: Latest
#include <Adafruit_NeoMatrix.h>
#include <gamma.h>
#define PIN 4
Adafruit_NeoMatrix matrix = Adafruit_NeoMatrix(32, 8, PIN,
NEO_MATRIX_TOP + NEO_MATRIX_RIGHT +
NEO_MATRIX_COLUMNS + NEO_MATRIX_PROGRESSIVE,
NEO_GRB + NEO_KHZ800);
const uint16_t colors[] = {
matrix.Color(255, 0, 0), matrix.Color(0, 255, 0), matrix.Color(0, 0, 255) };
#include "thingProperties.h"
bool enviando;
char *message;
int x;
int textlength;
int matrixWidth;
void setup() {
// Initialize serial and wait for port to open:
Serial.begin(115200);
// This delay gives the chance to wait for a Serial Monitor without blocking if none is found
delay(1500);
// Defined in thingProperties.h
initProperties();
// Connect to Arduino IoT Cloud
ArduinoCloud.begin(ArduinoIoTPreferredConnection);
/*
The following function allows you to obtain more information
related to the state of network and IoT Cloud connection and errors
the higher number the more granular information you’ll get.
The default is 0 (only errors).
Maximum is 4
*/
setDebugMessageLevel(4);
ArduinoCloud.printDebugInfo();
matrix.begin();
matrix.setTextWrap(false);
matrix.setBrightness(50);
matrix.setTextColor(colors[0]);
enviando = false;
indicador = false;
message = "Papa llamame";
matrix.setBrightness(40);
x = matrix.width();
textlength = strlen(message);
matrixWidth = textlength * 5 + textlength;
matrix.setCursor(0, 0);
}
void loop() {
ArduinoCloud.update();
indicador = 0;
}
void onEnviarChange() {
// Add your code here int counter = 0
if (enviar == HIGH){
matrix.setCursor(0, 0);
while(enviar == HIGH){
Serial.println("ON");
matrix.fillScreen(0);
matrix.setCursor(x, 0);
matrix.print(message);
if(--x < -matrixWidth) {
x = matrix.width();
}
matrix.show();
delay(70);
indicador = 1;
ArduinoCloud.update();
};
return;
}else{
indicador = 0;
Serial.println("OFF");
matrix.fillScreen(0);
matrix.setCursor(0, 0);
matrix.print(" ");
matrix.show();
}
}
void onIndicadorChange() {
Serial.println("LED");
}