Hello!
I recently started a project and decided to use Arduino to control my LEDs.
I am attempting to have multiple small LED strips fade in and out. Each strip needs to be a different solid color and will fade down to a brightness value of 50 (256 bit) and up to a value of 200 (256 bit).
Later, I will be adding more strips that will be doing a chasing rainbow effect, but for now, I will be thrilled to just get the fade working.
Ive been trying various different methods from the examples, other user's questions in the forum, and several YouTube videos.
I was able to get one strip on one pin to fade correctly using the delay function, but adding more strips on more pins caused problems. (One strip would fade at a time, followed by the next, instead of all at once.)
After this iteration, I found the Milli function and thought my problems were over. However, for some reason, I am unable to get this function to work at all.
I am using WS2812B RGB LEDs with an Arduino Mega and an external power supply.
It should be noted that I am an extreme novice at programming, so please forgive my ignorance.
Here is the code I am currently attempting to use--- it is a combination of several examples and several answered question on the forums. Ive been trying to get them to work together with little success.
#include "FastLED.h"
#define NUM_LEDS 20
#define NUM_STRIPS 1
int fadeAmount = 5; //brightness value to change by this amount
byte interval = 100; //how long between brightness changes
byte brightness = 50; //starting brightness
unsigned long currentMillis;
unsigned long startMillis;
CRGB leds[NUM_LEDS];
CLEDController *controllers[NUM_STRIPS];
void setup() {
controllers[0] = &FastLED.addLeds<WS2812B,8>(leds, NUM_LEDS); //setting up led strip, more to be added later
pinMode(8, OUTPUT); //making pin 8 output
startMillis = millis(); //set time to current time
}
void loop() {
currentMillis = millis(); //get current time
if (currentMillis - startMillis >= interval){
brightness = brightness + fadeAmount; // change the brightness for next time through the loop:
startMillis = millis(); //save time of update
}
if (brightness <= 50 )
{ // reverse the direction of the fading at the ends of the fade:
brightness = 50;
fadeAmount = +fadeAmount;
}
if (brightness >=200 )
{ // reverse the direction of the fading at the ends of the fade:
brightness = 200;
fadeAmount = -fadeAmount;
}
fill_solid(leds, NUM_LEDS, CRGB::DarkOrchid); //make led strip one color
controllers[0]->showLeds(brightness); //set controller0 (pin 8) at current brightness
}
I am using the "controllers" function from one of the examples as I plan to add more strips on individual pins once I am able to get the Milli fade working.
The code posted is making all the LEDs on the strip come on random colors and seemingly random brightness. None of which fade at all.
My hope is for a way to have the calculated brightness plug itself into the Controllers "ShowLed(brightness) code so it will update itself every loop.
I would greatly appreciate any assistance that can be provided.