#include <FastLED.h>
#define CHIPSET WS2812B
#define COLOR_ORDER GRB // Green (G), Red (R), Blue (B)
#define NUM_LEDS 96
#define DATA_PIN 3
#define BRIGHTNESS 255
#define VOLTS 5
#define MAX_AMPS 500 // value in milliamps
CRGB leds[NUM_LEDS]; // main LED array
CRGB test[10]; // set up separate array for merging with main LED array
// kind of a sprite
int indx = 0;
void setup() {
Serial.begin(115200);
FastLED.addLeds<CHIPSET,DATA_PIN,COLOR_ORDER>(leds, NUM_LEDS);
FastLED.setMaxPowerInVoltsAndMilliamps(VOLTS, MAX_AMPS);
FastLED.setBrightness(BRIGHTNESS);
FastLED.clear();
}
void loop() {
EVERY_N_MILLIS ( 40 ) {
leds[indx] = CRGB::White; // add the "running dot" after fades are applied
indx++;
if (indx > (NUM_LEDS-1)) indx = 0;
}
EVERY_N_MILLIS ( 100 ) {
// the &test[0] points to the array element directly
// it allows the choice of a starting point for the fade function
//Serial.println(test[0].r);
// fadeToBlackBy( test, 3, 10); // these two lines are the same
fadeToBlackBy(&test[0], 3, 10); // fade only first three elements in the array
fadeToBlackBy(&test[3], 1, 5); // fade only the third element in the array
if(test[0].r < 64){ // pixels faded enough
test[0]= CRGB(255, 11, 130); // reload pixels
test[1]= CRGB(221, 245, 6);
test[2]= CRGB(112, 16, 236);
test[3]= CRGB( 16, 236, 53);
//Serial.println("------------");
}
}
EVERY_N_MILLIS ( 10 ) { // timing macro available in FastLED library
// fade sections of leds[] array at different rates
// NOTE: "&leds[0]" and "leds" both point to the beginning of the array
fadeToBlackBy(&leds [0], 30, 3); // long tail
fadeToBlackBy(&leds[30], 30, 10); // mid tail
fadeToBlackBy(&leds[60], 30, 20); // short tail
fadeToBlackBy(&leds[90], 6, 1); // really long tail
memcpy(&leds[10], test, 4 * sizeof(CRGB)); // apply 4 pixels to leds[] array
memcpy(&leds[50], &test[0], 4 * sizeof(CRGB)); // apply 4 pixels to leds[] array
memcpy(&leds[80], &test[1], 3 * sizeof(CRGB)); // apply 3 pixels to leds[] array
FastLED.show(); // send pixel data to the LED strip
}
}