#include <MD_Parola.h>
#include <MD_MAX72xx.h>
#include <SPI.h>
// 模組設定:請根據你模組的型號選擇 FC16_HW 或 PAROLA_HW
#define HARDWARE_TYPE MD_MAX72XX::FC16_HW // 常見模組用 FC16_HW
#define MAX_DEVICES 4 // 4 片模組
#define CLK_PIN 13
#define DATA_PIN 11
#define CS_PIN 10
MD_Parola P = MD_Parola(HARDWARE_TYPE, CS_PIN, MAX_DEVICES);
// 跑馬燈參數
uint8_t scrollSpeed = 100; // 數值越大越慢
textEffect_t scrollEffect = PA_SCROLL_LEFT;
textPosition_t scrollAlign = PA_LEFT;
uint16_t scrollPause = 1000; // 停頓時間(毫秒)
#define BUF_SIZE 75
char curMessage[BUF_SIZE] = { "Hello World" };
char newMessage[BUF_SIZE] = { " " };
bool newMessageAvailable = false;
void readSerial() {
static char *cp = newMessage;
while (Serial.available()) {
*cp = (char)Serial.read();
if ((*cp == '\n') || (cp - newMessage >= BUF_SIZE - 2)) {
*cp = '\0';
cp = newMessage;
newMessageAvailable = true;
} else {
cp++;
}
}
}
void setup() {
Serial.begin(57600);
Serial.println("[Parola LED Display]");
Serial.println("請輸入訊息並按 Enter");
P.begin();
P.setIntensity(5); // 亮度 0~15
P.displayText(curMessage, scrollAlign, scrollSpeed, scrollPause, scrollEffect, scrollEffect);
}
void loop() {
if (P.displayAnimate()) {
if (newMessageAvailable) {
strcpy(curMessage, newMessage);
newMessageAvailable = false;
}
P.displayReset();
}
readSerial();
}
留言
張貼留言