#include <FastLED.h>
#define NUM_LEDS 100 // LED 數量
#define DATA_PIN 3
const int buttonPin = 4;
int buttonState = 0;
int i,j;
int Delay;
long Previous;
CRGB leds[NUM_LEDS];
void setup() {
pinMode(buttonPin, INPUT_PULLUP); // 按鍵輸入
pinMode(A0, INPUT); // 速度調整
FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS); // GRB ordering is assumed
}
void loop() {
Previous = millis();
j = analogRead(A0);
Delay = map(j, 0, 1024, 24, 120); //T = 1200/wpm; 24 = 50wpm, 120 = 10wpm
for (i = NUM_LEDS - 1; i > 0; i--) {
leds[i] = leds[i - 1]; //移位
}
buttonState = digitalRead(buttonPin);
if (buttonState == LOW)
leds[0] = CRGB::Green;
else
leds[0] = CRGB::Black;
FastLED.show();
while(millis()- Previous < Delay);
}