I am not very good in understanding and programming to arduino and did my program got somehow to run as I wanted to, but i will have an "startup sequence" in the script before the LEDs run.
I want all LEDs to light up in Red (maybe a fast Fade in, where i can define the speed) then light up for about 2 seconds , then fade out and after that this code should be executed
#include <FastLED.h>
double Pixel = 0;
double i = 0;
double Dimmer = 0;
#define NUM_LEDS 122
#define DATA_PIN 3
#define BRIGHTNESS 255
CRGB leds[NUM_LEDS];
int potPin0 = A0; // select the input pin for the potentiometer speed
int potPin1 = A1; // select the input pin for the potentiometer tail
int potPin2 = A2; // select the input pin for the potentiometer color
int potPin3 = A3; // select the input pin for the potentiometer brightness
int val0; // variable to store the value coming from the sensor
int val1; // variable to store the value coming from the sensor
int val2; // variable to store the value coming from the sensor
int val3; // variable to store the value coming from the sensor
void setup() {
Serial.begin(9600);
FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
FastLED.setBrightness(255);
}
void loop() {
val0 = analogRead(potPin0) / 41; // read the value from the sensor for speed
val1 = analogRead(potPin1) / 102.3; // read the value from the sensor for tail
val2 = analogRead(potPin2) / 4.01; // read the value from the sensor for color
val3 = analogRead(potPin3) / 4.01; // read the value from the sensor for brightness
if (val1 < 1) {
val1 = 1;
}
Serial.print("V0 = ");
Serial.print(val0);
Serial.print(" / ");
Serial.println(analogRead(potPin0));
Serial.print("V1 = ");
Serial.print(val1);
Serial.print(" / ");
Serial.println(analogRead(potPin1));
Serial.print("V2 = ");
Serial.print(val2);
Serial.print(" / ");
Serial.println(analogRead(potPin2));
Serial.print("V3 = ");
Serial.print(val3);
Serial.print(" / ");
Serial.println(analogRead(potPin3));
Serial.print("NUM_LEDS = ");
Serial.println(NUM_LEDS);
for (Pixel = 1; Pixel <= NUM_LEDS-5; Pixel++) {
fill_solid( &(leds[int(constrain(Pixel, 1, NUM_LEDS) - 0.1)]),
(constrain(int(5), 1, (NUM_LEDS - constrain(Pixel, 1, NUM_LEDS) + 1))),
CHSV( val2, 255, val3) );
FastLED.show();
for (Dimmer = 1; Dimmer <= 122; Dimmer++) {
leds[int(constrain(Dimmer, 1, NUM_LEDS) - 0.1)].fadeToBlackBy( val1*2.55 );
}
delay(val0);
}
for (Pixel = NUM_LEDS-4; Pixel >= 2; Pixel--) {
fill_solid( &(leds[int(constrain(Pixel, 1, NUM_LEDS) - 0.1)]),
(constrain(int(5), 1, (NUM_LEDS - constrain(Pixel, 1, NUM_LEDS) + 1))),
CHSV( val2, 255, val3) );
FastLED.show();
for (Dimmer = 1; Dimmer <= NUM_LEDS; Dimmer++) {
leds[int(constrain(Dimmer, 1, NUM_LEDS) - 0.1)].fadeToBlackBy( val1*2.55 );
}
delay(val0);
}
}
If you want it to run only once, put it in setup(). The FastLED library has many examples, including fade which you could use as a starting point. Try that. If you get stuck, post your best attempt, the errors and folks can help.
Okay i found a solution, just googled for fastled (which was the key btw) and found a fade out animation sample. Thanks for putting me in the right way
Can you explain what you tried to achieve in this complicated code? Why did you used a float math inside the array index? Why the Pixel iterator was declared as double?
Nevermind what i posted before, it was the very old sketch of the program. i also finally found out how to make the lights turn all on and fade out , after that the running light starts.... problem was my old arduino gave up the ghost and i think its impossible to read out the program , so i had to search on my hard drive and thought this was the right program But finally i found a backup from the last upload on my NAS and modified it
here's that code (a combination of neopixel and fastled now)
#include <FastLED_NeoPixel.h>
#include <FastLED.h>
#define MAX_P 122
CRGB leds[MAX_P];
Adafruit_NeoPixel strip = Adafruit_NeoPixel(MAX_P, 3, NEO_BRG + NEO_KHZ800);
int potPin0 = 0; // select the input pin for the potentiometer
int potPin1 = 1; // select the input pin for the potentiometer
int val0 = 0; // variable to store the value coming from the sensor
int val1 = 0; // variable to store the value coming from the sensor
int li=0;
int direction=+1;
uint32_t Red=strip.Color(255, 0, 0);
uint32_t Blank=strip.Color(0, 0, 0);
void setup() {
FastLED.addLeds<NEOPIXEL, 3>(leds, MAX_P);
FastLED.setBrightness(255);
FastLED.clear ();
fadeAnimation(255, 0, 0);
delay(500);
strip.begin();
strip.show(); // Initialize all pixels to 'off'
}
void loop() {
val0 = analogRead(potPin0) / 50; // read the value from the sensor
val1 = analogRead(potPin1) / 34.1; // read the value from the sensor
//decay
for(uint16_t i=0; i<MAX_P; i++) {
uint8_t r= (strip.getPixelColor(i)>>16) & 0xff;
r=(r*(69+val1))/100;
strip.setPixelColor(i, r, 0, 0);
}
strip.setPixelColor(li, Red);
if(li>(MAX_P-1)){
li=MAX_P;
direction=-1;
}else if(li<0){
li=-1;
direction=1;
}
li+=direction;
strip.show();
delay(val0);
}
void fadeAnimation(int red, int green, int blue){
float r, g, b;
// FADE OUT
for(int i = 255; i >= 0; i--) {
r = (i/256.0)*red;
g = (i/256.0)*green;
b = (i/256.0)*blue;
fill_solid(leds, MAX_P, CRGB(r, g, b));
FastLED.show();
delay(8);
}
}