@hans
Yes of course. Im also very happy if someone posts a final working code instead of snippets.
Here it is. Including LEDs outside the Gradient which light up by pushing a button (not very smart coding but it works).
#include <FastLED.h>
#define NUM_LEDS 70
#define LED_PIN 5
#define GRADIENT 64
#define buttonPin1 11
#define buttonPin2 10
#define buttonPin3 9
#define buttonPin4 8
#define buttonPin5 7
int buttonState1 = 0;
int buttonState2 = 0;
int buttonState3 = 0;
int buttonState4 = 0;
int buttonState5 = 0;
CRGB leds[NUM_LEDS];
CRGB GradientLeds[GRADIENT];
void setup() {
FastLED.addLeds<WS2812B, LED_PIN, GRB>(leds, NUM_LEDS);
pinMode(buttonPin1, INPUT_PULLUP);
pinMode(buttonPin2, INPUT_PULLUP);
pinMode(buttonPin3, INPUT_PULLUP);
pinMode(buttonPin4, INPUT_PULLUP);
pinMode(buttonPin5, INPUT_PULLUP);
makeGradient();
}
void loop()
{
meteorRain(0x33,0xff,0x00, 10 ,60 ,true, 40);
}
void meteorRain(byte red, byte green, byte blue, byte meteorSize, byte meteorTrailDecay, boolean meteorRandomDecay, int SpeedDelay)
{
for(int i = 0; i < GRADIENT+GRADIENT; i++)
{
// fade color to background color for all LEDs
for(int j=0; j < GRADIENT; j++) {
if( (!meteorRandomDecay) || (random(10) > 1) ) {
leds[j] = fadeTowardColor(leds[j], GradientLeds[j], meteorTrailDecay );
}
}
// draw meteor
for(int j = 0; j < meteorSize; j++) {
if( ( i-j < GRADIENT) && (i-j >= 0) ) {
leds[i-j] = GradientLeds[i - j];
leds[i-j].maximizeBrightness(50);
}
}
buttonState1 = digitalRead(buttonPin1); // read the state of the pushbutton value
if (buttonState1 == LOW) {
fill_solid(leds,GRADIENT, CRGB(0, 0, 0));
}
FastLED.show();
leds[66] = CRGB(0, 0, 0);
buttonState2 = digitalRead(buttonPin2); // read the state of the pushbutton value
if (buttonState2 == LOW) {
leds[66] = CRGB(0, 0, 255);
}
leds[67] = CRGB(0, 0, 0);
buttonState3 = digitalRead(buttonPin3); // read the state of the pushbutton value
if (buttonState3 == LOW) {
leds[67] = CRGB(255, 0, 255);
}
leds[68] = CRGB(0, 0, 0);
buttonState4 = digitalRead(buttonPin4); // read the state of the pushbutton value
if (buttonState4 == LOW) {
leds[68] = CRGB(255, 255, 0);
}
leds[69] = CRGB(0, 0, 0);
buttonState5 = digitalRead(buttonPin5); // read the state of the pushbutton value
if (buttonState5 == LOW) {
leds[69] = CRGB(0, 255, 255);
}
delay(SpeedDelay);
}
}
// Functions from Kriegsman example
CRGB fadeTowardColor( CRGB& cur, const CRGB& target, uint8_t amount)
{
nblendU8TowardU8( cur.red, target.red, amount);
nblendU8TowardU8( cur.green, target.green, amount);
nblendU8TowardU8( cur.blue, target.blue, amount);
return cur;
}
// function used by "fadeTowardColor"
void nblendU8TowardU8( uint8_t& cur, const uint8_t target, uint8_t amount)
{
if( cur == target) return;
if( cur < target ) {
uint8_t delta = target - cur;
delta = scale8_video( delta, amount);
cur += delta;
} else {
uint8_t delta = cur - target;
delta = scale8_video( delta, amount);
cur -= delta;
}
}
void makeGradient() {
// make a gradient (can take up to 4 colors, just using 2 for this example)
fill_gradient_RGB(GradientLeds, GRADIENT, CRGB(255,50,0), CRGB(255,70,0), CRGB(0,170,30), CRGB(0,255,255));
// Copy the gradient to the actual leds and show it.
for(int i=0; i<GRADIENT; i++) {
GradientLeds[i].nscale8( 15 );
}
FastLED.show();
}