#include <FastLED.h>
#define DATA_PIN 4
#define NUM_LEDS 194
CRGB leds[NUM_LEDS];
int index;
int direction = 1; // +1 or -1
int speed = 2; // 1 to 10 or so
void setup()
{
FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LEDS);
fill_solid(leds, NUM_LEDS, CRGB( 0, 0, 0));
FastLED.show();
FastLED.setBrightness(255);
}
void loop()
{
EVERY_N_MILLISECONDS(20) // every 20ms should be enough for human eye
{
myRainbow( index);
index += speed * direction;
if( index >= NUM_LEDS)
{
index -= NUM_LEDS;
}
if( index < 0)
{
index += NUM_LEDS;
}
}
EVERY_N_SECONDS(3) // change direction, just for fun
{
direction = -direction;
}
}
// Fill 194 leds with a hue from 0 to 255.
void myRainbow( int startLed)
{
const float hue_increment = float( 255) / float( NUM_LEDS);
int j = startLed;
for( int i=0; i<NUM_LEDS; i++, j++)
{
if( j >= NUM_LEDS) // index rolls beyond the array ?
{
j = 0; // wrap around
}
float thisHue = float( i) * hue_increment;
leds[j] = CHSV( int(thisHue), 255, 255);
}
FastLED.show();
}