#include <LedControl.h>
// DIN → D11, CS → D10, CLK → D13
LedControl lc(11, 13, 10, 4);//組數
int x=0, y=0;
uint8_t data[8]={
B01111110,
B00010001,
B00010001,
B01111110,
B00010001,
B00010001,
B00010001,
B00010001
};
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); // 清除顯示
// 顯示字母 "A"
//for (int i=0; i<8; i++)
// lc.setRow(0, i, reverseByte(data[i]));
//顯示一個LED
lc.setLed(0,0,0,true);
// Serial.begin(1115200);
}
void loop() {
// 無需更新
int v, h;
v=analogRead(A0);
h=analogRead(A1);
//Serial.print(v);
//Serial.print(", ");
//Serial.println(h);
//往左
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(10);
}