#include <LedControl.h>
// DIN → D11, CS → D10, CLK → D13
LedControl lc(11, 13, 10, 4); // DIN, CLK, CS, 組數
int x = 0, y = 0;
uint8_t data[8] = {
B00111100,
B01000010,
B01000010,
B01111110,
B01000010,
B01000010,
B01000010,
B00000000
};
byte reverseByte(byte data) {
byte reversed = 0;
for (int i = 0; i < 8; i++) {
reversed |= ((data >> i) & 0x01) << (7 - i);
}
return reversed;
}
void setup() {
lc.shutdown(0, false); // 啟動顯示
lc.setIntensity(0, 8); // 設置亮度(0-15)
lc.clearDisplay(0); // 清除顯示
//顯示一個LED
lc.setLed(0, 0, 0, true);
Serial.begin(115200);
}
void loop() {
// 無需更新
int v, h;
v = analogRead(A0);
h = analogRead(A1);
//往左
if (h >= 600) {
lc.setLed(y/8+(x/8)*2, x%8, y%8, false);
y++;
if (y > 15)
y = 15;
lc.setLed(y/8+(x/8)*2, x%8, y%8, true);
}
else if (h <= 400) { //往右
lc.setLed(y/8+(x/8)*2, x%8, y%8, false);
y--;
if (y < 0)
y = 0;
lc.setLed(y/8+(x/8)*2, x%8, y%8, true);
}
//往上
if (v <= 400) {
lc.setLed(y/8+(x/8)*2, x%8, y%8, false);
x++;
if (x > 15)
x = 15;
lc.setLed(y/8+(x/8)*2, x%8, y%8, true);
}
else if (v >= 600) { //往下
lc.setLed(y/8+(x/8)*2, x%8, y%8, false);
x--;
if (x < 0)
x = 0;
lc.setLed(y/8+(x/8)*2, x%8, y%8, true);
}
delay(200);
}