OK, multiple problems but here is a sketch that runs each pattern for 10 seconds each:-
#include <FastLED.h>
#define LED_PIN 5
#define NUM_LEDS 12
#define BRIGHTNESS 65
#define LED_TYPE NEOPIXEL
#define COLOR_ORDER GRB
// #define NUM_LEDS 12 these should have been removed because they are duplicates
//#define DATA_PIN 5
// Define the array of leds
CRGB leds[NUM_LEDS];
unsigned long startTime, timeToDoEffect;
//start of 1st "Fade" effect
// CRGB ledsFade[NUM_LEDS];
/////////// Speed ///////////
#define UPDATES_PER_SECOND 36
/////////////////////////////
CRGBPalette16 currentPalette;
TBlendType currentBlending;
extern CRGBPalette16 Preset;
extern const TProgmemPalette16 Preset_p PROGMEM;
void setup() {
setupFade();
// setupPush(); // no need for this
Serial.begin(9600);
}
void loop() {
Serial.println("going into Fade");
timeToDoEffect = 10 * 1000; // 10 seconds
startTime = millis();
while(millis() - startTime < timeToDoEffect) {
loopFade();
}
Serial.println("going into Push");
timeToDoEffect = 10 * 1000; // 10 seconds
startTime = millis();
while(millis() - startTime < timeToDoEffect) {
loopPush();
}
}
void setupFade() {
delay( 3000 ); // power-up safety delay - this is crap
FastLED.addLeds<NEOPIXEL, LED_PIN>(leds, NUM_LEDS);
FastLED.setBrightness( BRIGHTNESS );
currentPalette = Preset_p;
currentBlending = LINEARBLEND;
}
/* as this contains just a call in the setupFade function their is no need to have it
void setupPush() {
FastLED.addLeds<NEOPIXEL, LED_PIN>(leds, NUM_LEDS);
FastLED.setBrightness( BRIGHTNESS );
}
*/
void loopFade()
{
static uint8_t startIndex = 0;
startIndex = startIndex + 1;
FillLEDsFromPaletteColors( startIndex);
FastLED.show();
FastLED.delay(1000 / UPDATES_PER_SECOND);
}
void loopPush()
{
for (int dot = 0; dot < NUM_LEDS; dot++)
{
leds[dot] = CRGB::Red;
FastLED.show();
// clear this led for the next time around the loop
//leds[dot] = CRGB::Red; but you wern't changing it
delay(100);
leds[dot] = CRGB::Black;
}
for (int dot = 0; dot < NUM_LEDS; dot++)
{
leds[dot] = CRGB::Red;
FastLED.show();
// clear this led for the next time around the loop
leds[dot] = CRGB::Black;
delay(100);
}
for (int dot = 0; dot < NUM_LEDS; dot++)
{
leds[dot] = CRGB::Cyan;
FastLED.show();
// clear this led for the next time around the loop
// leds[dot] = CRGB::Cyan; but it was not clearing it
leds[dot] = CRGB::Black;
delay(100);
}
for (int dot = 0; dot < NUM_LEDS; dot++)
{
leds[dot] = CRGB::Cyan;
FastLED.show();
// clear this led for the next time around the loop
// leds[dot] = CRGB::Purple;
leds[dot] = CRGB::Black;
delay(100);
}
}
void FillLEDsFromPaletteColors( uint8_t colorIndex)
{
uint8_t brightness = 255;
for ( int i = 0; i < NUM_LEDS; i++) {
// was ledsFade
leds[i] = ColorFromPalette( currentPalette, colorIndex, brightness, currentBlending);
////////////////////////////////////////////////////////////
///////////////// Changes the width of each color //////////
colorIndex += 9;
////////////////////////////////////////////////////////////
}
}
// Not sure what this is doing - it is never called?
const TProgmemPalette16 Preset_p PROGMEM =
{
CRGB::Red,
CRGB::Red,
CRGB::Purple,
CRGB::Purple,
CRGB::Cyan,
CRGB::Cyan,
CRGB::Purple,
CRGB::Purple,
CRGB::Red,
CRGB::Red,
CRGB::Purple,
CRGB::Purple,
CRGB::Cyan,
CRGB::Cyan,
CRGB::Purple,
CRGB::Purple,
};
You had three main problems:-
-
Each effect needed repeated calls into it in order for you to see anything happening. Therefore I have added a while loop that keeps calling each effect for a set period of time.
-
Much more seriously was a lack of understanding of how FastLED works. You had defined two array buffers, one called ledFade and the other called led but you used the same pin number for each array. Therefore what the libiary did was to concatenate (join together) the two buffers. This meant that your buffer had twice the number of LEDs than you actually had and you could only see the first 12 of them the buffer. So when you commented out one effect's setup you reduced the buffer to match the number of LEDs you had. The solution was to not create two arrays but only one and address it in both effects using the same name.
-
Your push effect was faulty, your comment said you cleared the background but you just put the same colour back, I have changed this to black so you can see the advancing dot. Also your delay was far too short to see very much.
I have left in the debug print I used, you can remove this if you like. I have also commented out the things you need to remove once you have read them and understood what you needed to do. I also changed the BRIGHTNESS constant to save my eyes.
Edit:- Given that I have spent the last hour on this I think posting four minutes apart is not bad. ![]()