這一次我們要換個方向點亮 LED,先逐一點亮前面的 16 只 LED,再往背面方向點亮過去。
靠近 USB 和電源插頭那一端是背面。
程式碼
//2017-01-01 LED_Cube4_02.ino
//從前面到背面垂直逐一點亮 LED
#define CUBE_SIZE 4
#define PLANE_SIZE CUBE_SIZE*CUBE_SIZE
#define PLANE_TIME 20
#define LED_TIME 200
int LEDPin[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, A0, A1};
int PlanePin[] = {A2 , A3, A4, A5};
void setup()
{
int pin;
for (pin = 0; pin < PLANE_SIZE; pin++) {
pinMode(LEDPin[pin], OUTPUT);
digitalWrite(LEDPin[pin], LOW);
}
for (pin = 0; pin < CUBE_SIZE; pin++) {
pinMode(PlanePin[pin], OUTPUT);
digitalWrite(PlanePin[pin], HIGH);
}
}
void loop()
{
for (int led = 0; led < PLANE_SIZE; led++)
{
digitalWrite(LEDPin[led], HIGH);
for (int plane = 0; plane < CUBE_SIZE; plane++)
{
digitalWrite(PlanePin[plane], LOW);
delay(LED_TIME);
digitalWrite(PlanePin[plane], HIGH);
}
digitalWrite(LEDPin[led], LOW);
delay(PLANE_TIME);
}
}
來看看影片
相關連結
1. [LED] 玩轉光立方 LED Cube 4x4x4 for Arduino UNO http://pizgchen.blogspot.tw/2016/12/led-4x4x4-for-arduino-uno.html
2. [LED] 玩轉光立方 LED Cube 4x4x4 for Arduino UNO -- 程式3 http://pizgchen.blogspot.tw/2017/01/led-led-cube-4x4x4-for-arduino-uno-3.html
他上傳寫有錯誤欸
回覆刪除您有用涵式庫嗎?