#include <FastLED.h>
#define LED_PIN 3
#define NUM_LEDS 256
const int SW = 7; //左方燈開關
int val;
CRGB leds[NUM_LEDS];
void setup() {
FastLED.addLeds<WS2812, LED_PIN, GRB>(leds, NUM_LEDS);
pinMode(SW,INPUT_PULLUP);
//設定數位第 7 腳為輸入模式 ( 使用內部上拉電阻 )。
}
void loop () {
val=digitalRead(SW); //讀取按鍵狀態。
if(val==LOW) //按鍵開關被按一下?
// for(int counter = 0; counter < 10; counter++) //這邊也可以方向燈執行10次閃爍
{
leftLight ();}
}
void rearlight () {
leds[37] = CRGB(255, 0, 0);
leds[38] = CRGB(255, 0, 0);
leds[39] = CRGB(255, 0, 0);
leds[40] = CRGB(255, 0, 0);
leds[41] = CRGB(255, 0, 0);
leds[56] = CRGB(255, 0, 0);
leds[72] = CRGB(255, 0, 0);
leds[88] = CRGB(255, 0, 0);
FastLED.show();
}
void leftLight () {
for(int i=0;i<10;i++) //這邊也可以執行方向燈執行10次閃爍
{
leds[142] = CRGB(255, 255, 0);
leds[143] = CRGB(255, 255, 0);
// FastLED.show();
// delay(300);
leds[126] = CRGB(255, 255, 0);
leds[127] = CRGB(255, 255, 0);
FastLED.show();
delay(300);
leds[110] = CRGB(255, 255, 0);
leds[111] = CRGB(255, 255, 0);
// FastLED.show();
// delay(300);
leds[94] = CRGB(255, 255, 0);
leds[95] = CRGB(255, 255, 0);
FastLED.show();
delay(300);
leds[78] = CRGB(255, 255, 0);
leds[79] = CRGB(255, 255, 0);
// FastLED.show();
// delay(300);
leds[62] = CRGB(255, 255, 0);
leds[63] = CRGB(255, 255, 0);
FastLED.show();
delay(300);
leds[46] = CRGB(255, 255, 0);
leds[47] = CRGB(255, 255, 0);
// FastLED.show();
// delay(300);
leds[30] = CRGB(255, 255, 0);
leds[31] = CRGB(255, 255, 0);
FastLED.show();
delay(300);
leds[14] = CRGB(255, 255, 0);
leds[15] = CRGB(255, 255, 0);
FastLED.show();
delay(200);
FastLED.clear(); //將所有LED熄滅清除 這兩行很重要
FastLED.show(); //刷新LED的色彩顯示 這兩行很重要
}
}