Hello everyone,
I wrote this function " fade_down() " which should fade out all LED lights. The function works fine, but the problem is the function doesn't go for the next instruction which is gradually_red();. It repeats the loop() again and again. I don't know what I did wrong.
thanks.
#include <FastLED.h>
#include "FastLED_RGBW.h"
#define LED_PIN 4
#define LED_PIN2 7
#define LED_PIN3 8
#define NUM_LEDS 5
#define NUM_LEDS2 5
#define NUM_LEDS3 5
CRGBW leds[NUM_LEDS];
CRGB *ledsRGB = (CRGB *) &leds[0];
CRGBW leds2[NUM_LEDS2];
CRGB *ledsRGB2 = (CRGB *) &leds2[0];
CRGBW leds3[NUM_LEDS3];
CRGB *ledsRGB3 = (CRGB *) &leds3[0];
int fadeAmount = 255;
int brightness = 0;
int N=0;
void setup() {
FastLED.addLeds<WS2812B, LED_PIN, RGB>(ledsRGB, getRGBWsize(NUM_LEDS));
FastLED.addLeds<WS2812B, LED_PIN2, RGB>(ledsRGB2, getRGBWsize(NUM_LEDS2));
FastLED.addLeds<WS2812B, LED_PIN3, RGB>(ledsRGB3, getRGBWsize(NUM_LEDS3));
}
void loop() {
gradually_white();
FastLED.delay(110);
gradually_white2();
FastLED.delay(110);
gradually_white3();
FastLED.delay(1500);
fade_down();
FastLED.delay(1500);
gradually_red();
fade_down();
FastLED.clear();
FastLED.delay(110);
}
/*
void fade_down() {
for(int i = 0; i < NUM_LEDS; i-- )
{
ledsRGB[i].setRGB(255,255,255);
ledsRGB[i].fadeLightBy(brightness);
}
FastLED.show();
brightness = brightness + fadeAmount;
if(brightness == 0 || brightness == 255)
{
fadeAmount = -fadeAmount ;
}
delay(9);
}
*/
void fade_down() {
for(int i=255;i>=0;i--) {
FastLED.setBrightness(i);
leds[i] = CRGB(255,255,255);
FastLED.show();
brightness = brightness + fadeAmount;
if(brightness == 0 || brightness == 255)
{
fadeAmount = -fadeAmount ;
}
delay(15);
}
}
void gradually_white(){
leds[4] = CRGB(255, 255, 255);
FastLED.show();
delay(110);
leds[3] = CRGB(255, 255, 255);
FastLED.show();
delay(110);
leds[2] = CRGB(255, 255, 255);
FastLED.show();
delay(110);
leds[1] = CRGB(255, 255, 255);
FastLED.show();
delay(110);
leds[0] = CRGB(255, 255, 255);
FastLED.show();
delay(110);
delay(600);
}
void gradually_white2(){
leds2[3] = CRGB(255, 255, 255);
FastLED.show();
delay(110);
leds2[2] = CRGB(255, 255, 255);
FastLED.show();
delay(110);
leds2[1] = CRGB(255, 255, 255);
FastLED.show();
delay(110);
leds2[0] = CRGB(255, 255, 255);
FastLED.show();
delay(110);
}
void gradually_white3(){
FastLED.delay(600);
leds3[3] = CRGB(255, 255, 255);
FastLED.show();
delay(110);
leds3[2] = CRGB(255, 255, 255);
FastLED.show();
delay(110);
leds3[1] = CRGB(255, 255, 255);
FastLED.show();
delay(110);
leds3[0] = CRGB(255, 255, 255);
FastLED.show();
delay(110);
}
void gradually_red(){
leds[3]=CRGB::Red;
FastLED.show();
delay(110);
leds[2]=CRGB::Red;
FastLED.show();
delay(110);
leds[1]=CRGB::Red;
FastLED.show();
delay(110);
leds[0]=CRGB::Red;
FastLED.show();
delay(110);
leds2[3]=CRGB::Red;
FastLED.show();
delay(110);
leds2[2]=CRGB::Red;
FastLED.show();
delay(110);
leds2[1]=CRGB::Red;
FastLED.show();
delay(110);
leds2[0]=CRGB::Red;
FastLED.show();
delay(110);
delay(600);
leds3[3]=CRGB::Red;
FastLED.show();
delay(110);
leds3[2]=CRGB::Red;
FastLED.show();
delay(110);
leds3[1]=CRGB::Red;
FastLED.show();
delay(110);
leds3[1]=CRGB::Red;
FastLED.show();
delay(110);
leds3[0]=CRGB::Red;
FastLED.show();
delay(110);
}