Hi, I have updated the code.
I am having following problems:
1-When new message comes, it scrolls but only once. I want it to scroll continuously.
2-If i dont use displayclear, display freezes:
} else {
P.displayClear(); //display freezes on getting new message if i dont use this line here
P.displayText(message , PA_CENTER, 10, 0, PA_PRINT, PA_SCROLL_LEFT); //initialise all text output to be in the middle
P.displayAnimate();
P.displayReset();
}
3-it shows maximum 6-7 alphabets. is there a way to display entire text?
I would really appreciate the help. Thank you
Here is the entire code for reference:
#include <WiFi.h>
#include <PubSubClient.h>
#include <MD_Parola.h>
#include <MD_MAX72xx.h>
#include <SPI.h>
#define HARDWARE_TYPE MD_MAX72XX::FC16_HW
#define MAX_DEVICES 4 //If you're only using a single 32x8 display then please set this to 4.
#define CLK_PIN D18 //green
#define DATA_PIN D23 //orange
#define CS_PIN 5 //yellow
MD_Parola P = MD_Parola(HARDWARE_TYPE, CS_PIN, MAX_DEVICES);
#define LED 2
//Enter your wifi credentials
const char* ssid = "monika";
const char* password = "12345678";
//Enter your mqtt server configurations
const char* mqttServer = "broker.hivemq.com"; //Enter Your mqttServer address
const int mqttPort = 1883; //Port number
//const char* mqttUser = "seVU93RhYk"; //User
//const char* mqttPassword = "c5xFF6zhxT"; //Password
WiFiClient espClient;
PubSubClient client(espClient);
void setup() {
delay(1000);
pinMode(LED,OUTPUT);
Serial.begin(115200);
P.begin();
P.setIntensity(0);
P.displayClear();
//P.displayScroll("HELLO MONIKA", PA_CENTER, PA_SCROLL_LEFT,30); //initialise all text output to be in the middle
//P.displayAnimate();
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.println("Connecting to WiFi..");
}
Serial.print("Connected to WiFi :");
Serial.println(WiFi.SSID());
client.setServer(mqttServer, mqttPort);
client.setCallback(MQTTcallback);
while (!client.connected()) {
Serial.println("Connecting to MQTT...");
if (client.connect("ESP32" )) {
Serial.println("connected to MQTT");
P.displayText("MQTT ON" , PA_CENTER, 50, 0, PA_PRINT, PA_SCROLL_LEFT); //initialise all text output to be in the middle
P.displayAnimate();
} else {
Serial.print("failed with state ");
Serial.println(client.state()); //If you get state 5: mismatch in configuration
delay(2000);
}
}
client.publish("esp/test2", "Hello from ESP32");
client.subscribe("esp/test2");
}
void MQTTcallback(char* topic, byte* payload, unsigned int length) {
Serial.print("Message arrived in topic: ");
Serial.println(topic);
Serial.print("Message:");
char message[length + 1];
message[length] = '\0'; // end of string
for (int i = 0; i < length; i++) {
message[i] = (char)payload[i];
}
Serial.print(message);
//String message;
//for (int i = 0; i < length; i++) {
//message = message + (char)payload[i]; //Conver *byte to String
//}
//message = message + '\0'; // EOL
//Serial.print(message);
//P.displayText(message)
//P.displayAnimate();
//delay(10000);
if(message == "on") {
digitalWrite(LED,HIGH); //LED on
P.displayClear();
P.displayText("LED on" , PA_CENTER, 50, 0, PA_PRINT, PA_SCROLL_LEFT); //initialise all text output to be in the middle
P.displayAnimate();
}
if(message == "off") {
digitalWrite(LED,LOW);
P.displayClear();
P.displayText("Off" , PA_CENTER, 50, 0, PA_PRINT, PA_SCROLL_LEFT); //initialise all text output to be in the middle
P.displayAnimate();
} else {
P.displayClear();
P.displayText(message , PA_CENTER, 10, 0, PA_PRINT, PA_SCROLL_LEFT); //initialise all text output to be in the middle
P.displayAnimate();
}
Serial.println();
Serial.println("-----------------------");
}
void loop() {
client.loop();
if (P.displayAnimate()) {
P.displayReset();
}
}