#define BLYNK_TEMPLATE_ID "TMPL6KIpAAye6"
#define BLYNK_TEMPLATE_NAME "lab32"
#define BLYNK_AUTH_TOKEN "35uz59lScXZ5ovIuposTqoe8aIGEC4kx"
#include <MD_Parola.h>
#include <SPI.h>
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
#define BLYNK_PRINT Serial
char auth[] = BLYNK_AUTH_TOKEN;
char ssid[] = "Wokwi-GUEST";
char pass[] = "";
// Cài đặt phần cứng
#define HARDWARE_TYPE MD_MAX72XX::PAROLA_HW
#define MAX_DEVICES 8 // Số lượng module LED
#define CLK_PIN 18
#define DATA_PIN 23
#define CS_PIN 5
#define BUF_SIZE 512
MD_Parola P = MD_Parola(HARDWARE_TYPE, CS_PIN, MAX_DEVICES);
// Các tham số hiển thị
uint8_t frameDelay = 25;
char user1Message[BUF_SIZE] = "Hello User 1!";
char user2Message[BUF_SIZE] = "Hello User 2!";
bool newUser1Message = false;
bool newUser2Message = false;
void setup() {
Serial.begin(9600);
delay(1000);
// Khởi tạo LED matrix
P.begin();
P.displayClear();
P.displaySuspend(false);
// Chia vùng hiển thị: Zone 0 (module 0-3), Zone 1 (module 4-7)
P.setZone(0, 0, 3); // Zone 0: Module 0-3
P.setZone(1, 4, 7); // Zone 1: Module 4-7
// Hiển thị thông điệp mặc định
P.displayZoneText(0, user1Message, PA_LEFT, frameDelay, PA_SCROLL_LEFT);
P.displayZoneText(1, user2Message, PA_LEFT, frameDelay, PA_SCROLL_LEFT);
P.displayAnimate();
// Kết nối WiFi và Blynk
Blynk.begin(auth, ssid, pass);
Serial.println("Connected to Blynk.");
}
void loop() {
Blynk.run();
// Kiểm tra và cập nhật thông điệp của người dùng 1
if (newUser1Message) {
P.displayZoneText(0, user1Message, PA_LEFT, frameDelay, PA_SCROLL_LEFT);
newUser1Message = false;
}
// Kiểm tra và cập nhật thông điệp của người dùng 2
if (newUser2Message) {
P.displayZoneText(1, user2Message, PA_LEFT, frameDelay, PA_SCROLL_LEFT);
newUser2Message = false;
}
// Hiển thị hiệu ứng
if (P.displayAnimate()) {
Serial.println("Updating display animation");
}
}
// Xử lý pin ảo để nhận thông điệp từ người dùng 1
BLYNK_WRITE(V0) {
strncpy(user1Message, param.asString(), BUF_SIZE);
newUser1Message = true;
}
// Xử lý pin ảo để nhận thông điệp từ người dùng 2
BLYNK_WRITE(V1) {
strncpy(user2Message, param.asString(), BUF_SIZE);
newUser2Message = true;
}