#include <LedControl.h>
// LED Matrix 腳位設定
#define dataPin 5 // DIN
#define loadPin 6 // CS
#define clockPin 7 // CLK
LedControl ledMatrix = LedControl(dataPin, clockPin, loadPin, 1);
// 十字架圖案定義
const byte crossSmall[8] = {
B00000000, B00000000, B00011000, B00111100,
B00011000, B00000000, B00000000, B00000000
};
const byte crossMedium[8] = {
B00000000, B00011000, B01111110, B01111110,
B00011000, B00011000, B00011000, B00000000
};
const byte crossLargeSimple[8] = {
B00011000, B00011000, B11111111, B11111111,
B00011000, B00011000, B00011000, B00011000
};
const byte crossLargeDecorated[8] = {
B00011000, B00011000, B11111111, B11111111,
B00011000, B01011000, B00011000, B00011000
};
const byte crossMaxDrip[8] = {
B00011000, B00011000, B11111111, B11111111,
B00011000, B00011000, B00011000, B01011000
};
// 河流圖案定義
const byte riverStart[8] = {
B00100000, B00011000, B00001100, B00000000,
B00000000, B00000000, B00000000, B00000000
};
const byte riverHalf[8] = {
B00100000, B00011000, B00001100, B00011000,
B00110000, B00011000, B00000000, B00000000
};
const byte riverFull[8] = {
B00100000, B00011000, B00001100, B00011000,
B00110000, B00011100, B00000111, B00000011
};
// 圖案陣列與延遲時間
const byte* patternList[] = {
crossSmall, crossMedium, crossLargeSimple,
crossLargeDecorated, crossMaxDrip,
riverStart, riverHalf, riverFull
};
const int patternDelays[] = {300, 300, 700, 300, 300, 300, 300, 500};
void setup() {
ledMatrix.shutdown(0, false); // 啟動 LED 模組
ledMatrix.setIntensity(0, 5); // 設定亮度(0~15)
ledMatrix.clearDisplay(0); // 清除顯示
}
void loop() {
for (int i = 0; i < 8; i++) {
displayPattern(patternList[i]);
delay(patternDelays[i]);
}
ledMatrix.clearDisplay(0);
delay(500);
}
// 顯示圖案函數
void displayPattern(const byte pattern[8]) {
for (int row = 0; row < 8; row++) {
ledMatrix.setRow(0, row, pattern[row]);
}
}
留言
張貼留言