thankyou
Iam not able to scroll the text can you pls once check the following code and any changes?
#include <WiFi.h>
#include <PubSubClient.h>
const char* ssid = “ffdfdf”;
const char* password = “hyfrrd”;
char mqttServer = “test.mosquitto.org”;
int mqttPort = 1883;
const char mqtt_client_name = “ESPYSssss2111”;
const char* mqtt_pub_topic = “/ys/testpub”; //The topic to which our client will publish
const char* mqtt_sub_topic = “/ys/testsub”; //The topic to which our client will subscribe
WiFiClient client;
PubSubClient mqttClient(client);
#define PANEL_RES_X 32 // Number of pixels wide of each INDIVIDUAL panel module.
#define PANEL_RES_Y 16 // Number of pixels tall of each INDIVIDUAL panel module.
#define NUM_ROWS 4 // Number of rows of chained INDIVIDUAL PANELS
#define NUM_COLS 4 // Number of INDIVIDUAL PANELS per ROW
#define PANEL_CHAIN NUM_ROWSNUM_COLS // total number of panels chained one to another
#define Matrix_width NUM_ROWSPANEL_RES_X
#define SERPENT true
#define TOPDOWN true
String str=" ";
String str1=“Medplus offers”;
#include <ESP32-VirtualMatrixPanel-I2S-DMA.h>
#include <Fonts/FreeMonoBold9pt7b.h>
MatrixPanel_I2S_DMA *dma_display = nullptr;
VirtualMatrixPanel *virtualDisp = nullptr;
void callback(char* topic, byte* payload, unsigned int length)
{
str=“”;
virtualDisp->clearScreen();
Serial.print("Message received from: ");
Serial.println(topic);
for (int i = 0; i < length; i++)
{
Serial.print((char)payload[i]);
str += (char)payload[i];
}
virtualDisp->setFont(&FreeMonoBold9pt7b);
scroll_text(20,50,str,0,240,255);
// virtualDisp->setTextColor(virtualDisp->color565(0, 0, 255));
// virtualDisp->setTextSize(1);
// virtualDisp->setCursor(6, virtualDisp->height()-20);
// virtualDisp->print(str);
Serial.println("the string is ");
Serial.println(str);
}
void scroll_text(uint8_t ypos,unsigned long scroll_delay, String text, uint8_t colorR, uint8_t colorG, uint8_t colorB)
{
uint16_t text_length = text.length();
virtualDisp->setTextColor(virtualDisp->color565(colorR, colorG, colorB));
for (int xpos=Matrix_width; xpos>-(Matrix_width+text_length*7); xpos–)
{
virtualDisp->setTextColor(virtualDisp->color565(colorR, colorG, colorB));
virtualDisp->setCursor(xpos, virtualDisp->height()-ypos);
virtualDisp->clearScreen();
virtualDisp->setTextSize(1);
virtualDisp->print(text);
delay(scroll_delay);
yield();
delay(scroll_delay/5);
yield();
}
}
void setup() //Setup!
{
delay(200);
Serial.begin(115200);
WiFi.mode(WIFI_STA); //The WiFi is in station mode
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print(“.”);
}
Serial.println(“”); Serial.print(“WiFi connected to: “); Serial.println(ssid); Serial.println(“IP address: “); Serial.println(WiFi.localIP());
delay(2000);
mqttClient.setServer(mqttServer, mqttPort);
mqttClient.setCallback(callback);
Serial.println(””); Serial.println(””); Serial.println(“”);
HUB75_I2S_CFG mxconfig
(
PANEL_RES_X, // module width
PANEL_RES_Y, // module height
PANEL_CHAIN // chain length
);
if (NUM_ROWS <= 1)
{
Serial.println(F(“There is no reason to use the VirtualDisplay class for a single horizontal chain and row!”));
}
dma_display = new MatrixPanel_I2S_DMA(mxconfig);
dma_display->setBrightness8(192); // range is 0-255, 0 - 0%, 255 - 100%
if( not dma_display->begin() )
Serial.println(“****** I2S memory allocation failed ***********”);
virtualDisp = new VirtualMatrixPanel((*dma_display), NUM_ROWS, NUM_COLS, PANEL_RES_X, PANEL_RES_Y, SERPENT, TOPDOWN);
virtualDisp->fillScreen(virtualDisp->color444(0, 0, 0));
delay(3000);
}
void reconnect()
{
if (!mqttClient.connected())
{
while (!mqttClient.connected())
{
if(mqttClient.connect(mqtt_client_name))
{
Serial.println(“MQTT Connected!”);
mqttClient.subscribe(mqtt_sub_topic);
}
else
{
Serial.print(“.”);
}
}
}
}
void loop()
{
reconnect();
mqttClient.loop();
delay(500);
//scroll_text(20,50,str,0,240,255);
virtualDisp->drawRect(1,1, virtualDisp->width()-2, virtualDisp->height()-2, virtualDisp->color565(255,0,0));
}