#define BLYNK_TEMPLATE_ID "TMPLi3TvcvWa" //Budhadodo account
#define BLYNK_TEMPLATE_NAME "DHT sensor"
#define BLYNK_AUTH_TOKEN "9lubYbbEcu8dlM-BRgJ4pfI_1b6sSqvr"
#define BLYNK_PRINT Serial
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
#include <MD_Parola.h> // include MajicDesigns Parola library
#include <MD_MAX72xx.h> // include MajicDesigns MAX72xx LED matrix library
#include <SPI.h>
// Your WiFi credentials
char auth[] = BLYNK_AUTH_TOKEN;
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "Wokwi-GUEST";
char pass[] = "";
// Hardware setup
#define HARDWARE_TYPE MD_MAX72XX::PAROLA_HW //FC16_HW (for real HW)
#define MAX_DEVICES 16 // If you're only using a single 32x8 display, set this to 4.
#define CLK_PIN 18 // cyan
#define DATA_PIN 23 // yellow
#define CS_PIN 15 // green
// define number of total cascaded modules
// Scrolling parameters
uint8_t frameDelay = 25; // default frame delay value
textPosition_t scrollEffect = PA_LEFT; // default scroll effect is left
uint8_t scrollSpeed = 75; // default scroll speed value (change as needed)
bool scrollDirectionLeft = false; // flag to determine the scroll direction
bool invertDisplay = false; // flag to determine if the display is inverted
uint8_t brightnessLevel = 0; // default brightness level (range: 1-15)
// Global message buffers shared by Blynk and Scrolling functions
#define BUF_SIZE 512
char curMessage[BUF_SIZE];
char newMessage[BUF_SIZE];
bool newMessageAvailable = false;
// Define the LED matrix object
MD_Parola P = MD_Parola(HARDWARE_TYPE, CS_PIN, MAX_DEVICES);
void setup() {
// Initialize serial communication
Serial.begin(115200);
// Connect to Wi-Fi
WiFi.begin(ssid, pass);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("Wi-Fi connected");
// Initialize Blynk
Blynk.begin(auth, ssid, pass);
// Blynk.begin(auth, ssid, pass, "blr1.blynk.cloud", 80);
//Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass, IPAddress(192,168,1,100), 8080);
// Set up the scrolling display
P.begin();
P.displayClear();
P.displaySuspend(false);
P.displayScroll(curMessage, scrollEffect, scrollDirectionLeft ? PA_SCROLL_RIGHT : PA_SCROLL_LEFT, frameDelay);
// Register a virtual pin handler for receiving messages from Blynk
Blynk.virtualWrite(V0, "Developed by Budhaditya");
// Set up the initial message as the IP address
sprintf(curMessage, ".");
Serial.println(curMessage);
}
void loop() {
// Run Blynk
Blynk.run();
// Check if a new message is available and update the display
if (newMessageAvailable) {
strcpy(curMessage, newMessage);
newMessageAvailable = false;
P.displayReset();
}
// Animate the display
if (P.displayAnimate()) {
if (newMessageAvailable) {
strcpy(curMessage, newMessage);
newMessageAvailable = false;
}
P.displayReset();
}
}
// Blynk virtual pin handler for receiving messages
BLYNK_WRITE(V0) {
strncpy(newMessage, param.asString(), BUF_SIZE);
newMessageAvailable = true;
}
// Blynk virtual pin handler for receiving scroll speed
BLYNK_WRITE(V1) {
scrollSpeed = param.asInt();
frameDelay = map(scrollSpeed, 0, 150, 150, 0);
P.setSpeed(frameDelay); // Update the scroll speed
}
// Blynk virtual pin handler for receiving scroll direction
BLYNK_WRITE(V2) {
scrollDirectionLeft = param.asInt();
P.displayClear();
P.displayScroll(curMessage, scrollEffect, scrollDirectionLeft ? PA_SCROLL_RIGHT : PA_SCROLL_LEFT, frameDelay);
}
// Blynk virtual pin handler for receiving invert display
BLYNK_WRITE(V3) {
invertDisplay = param.asInt();
P.displayClear();
P.setInvert(invertDisplay);
}
// Blynk virtual pin handler for receiving brightness level
BLYNK_WRITE(V4) {
brightnessLevel = param.asInt();
P.setIntensity(brightnessLevel); // Set the brightness level
}