Hi guys, I have a few questions!! I made a heart image by using

Hi guys, I have a few questions!!

I made a heart image by using fastLED code, but it just blinks and it doesn’t move…

Would you look at my code and tell me the problem :slight_smile:

my code:

#include <FastLED.h>

#define LED_PIN1 7
#define LED_PIN2 8
#define LED_PIN3 9
#define LED_PIN4 10
#define LED_PIN5 11
#define NUM_LEDS 25
#define BRIGHTNESS 64
#define LED_TYPE WS2811
#define COLOR_ORDER GRB
CRGB leds1[NUM_LEDS];
CRGB leds2[NUM_LEDS];
CRGB leds3[NUM_LEDS];
CRGB leds4[NUM_LEDS];
CRGB leds5[NUM_LEDS];

#define UPDATES_PER_SECOND 100

CRGBPalette16 currentPalette;
TBlendType currentBlending;

extern CRGBPalette16 myRedWhiteBluePalette;
extern const TProgmemPalette16 myRedWhiteBluePalette_p PROGMEM;

void setup() {

delay( 3000 ); // power-up safety delay
FastLED.addLeds<LED_TYPE, LED_PIN1, COLOR_ORDER>(leds1, NUM_LEDS).setCorrection( TypicalLEDStrip );
FastLED.addLeds<LED_TYPE, LED_PIN2, COLOR_ORDER>(leds2, NUM_LEDS).setCorrection( TypicalLEDStrip );
FastLED.addLeds<LED_TYPE, LED_PIN3, COLOR_ORDER>(leds3, NUM_LEDS).setCorrection( TypicalLEDStrip );
FastLED.addLeds<LED_TYPE, LED_PIN4, COLOR_ORDER>(leds4, NUM_LEDS).setCorrection( TypicalLEDStrip );
FastLED.addLeds<LED_TYPE, LED_PIN5, COLOR_ORDER>(leds5, NUM_LEDS).setCorrection( TypicalLEDStrip );
FastLED.setBrightness(  BRIGHTNESS );

currentPalette = Heart;
currentBlending = LINEARBLEND;

}

void loop()
{
ChangePalettePeriodically();

static uint8_t startIndex = 0;

startIndex = startIndex + 1; /* motion speed */

FillLEDsFromPaletteColors(startIndex);

FastLED.show();
FastLED.delay(1000 / UPDATES_PER_SECOND);

}

void FillLEDsFromPaletteColors( uint8_t colorIndex)
{
uint8_t brightness = 255;
colorIndex += 16;

for( int i = 0; i < NUM_LEDS;i++) {
    if(i%6==2 || i%6==4) 
      leds1[i] = ColorFromPalette( currentPalette, colorIndex, brightness, currentBlending);
}
for( int i = 0; i < NUM_LEDS;i++) {
    if(i%6==0) {
    }
    else{
    leds2[i] = ColorFromPalette( currentPalette, colorIndex, brightness, currentBlending);
    leds3[i] = ColorFromPalette( currentPalette, colorIndex, brightness, currentBlending);
    }
}
for( int i = 0; i < NUM_LEDS;i++) {
    if(i%6==2 || i%6==3 || i%6==4) 
       leds4[i] = ColorFromPalette( currentPalette, colorIndex, brightness, currentBlending);
}
    
for( int i = 0; i < NUM_LEDS;i++) {
    if(i%6==3) 
      leds5[i] = ColorFromPalette( currentPalette, colorIndex, brightness, currentBlending);
}

}

void ChangePalettePeriodically()
{
float secondHand = (millis() / 1000) % 60;
static uint8_t lastSecond = 99;

if( lastSecond != secondHand) {
    lastSecond = secondHand;

// if( secondHand == 0) { currentPalette = Christmas; currentBlending = LINEARBLEND; }
// if( secondHand == 10) { currentPalette = RainbowStripeColors_p; currentBlending = NOBLEND; }
// if( secondHand == 30) { currentPalette = Blossom; currentBlending = LINEARBLEND; }
// if( secondHand == 20) { SetupPurpleAndGreenPalette(); currentBlending = LINEARBLEND; }
// if( secondHand == 25) { SetupTotallyRandomPalette(); currentBlending = LINEARBLEND; }
// if( secondHand == 30) { SetupBlackAndWhiteStripedPalette(); currentBlending = NOBLEND; }
// if( secondHand == 35) { SetupBlackAndWhiteStripedPalette(); currentBlending = LINEARBLEND; }
// if( secondHand == 40) { currentPalette = CloudColors_p; currentBlending = LINEARBLEND; }
// if( secondHand == 50) { currentPalette = Spring; currentBlending = LINEARBLEND; }
// if( secondHand == 50) { currentPalette = myRedWhiteBluePalette_p; currentBlending = NOBLEND; }
// if( secondHand == 55) { currentPalette = myRedWhiteBluePalette_p; currentBlending = LINEARBLEND; }
}
}

// This function fills the palette with totally random colors.
void SetupTotallyRandomPalette()
{
for( int i = 0; i < 16; i++) {
currentPalette[i] = CHSV( random8(), 255, random8());
}
}

void SetupBlackAndWhiteStripedPalette()
{
// ‘black out’ all 16 palette entries…
fill_solid( currentPalette, 16, CRGB::Black);
// and set every fourth one to white.
currentPalette[0] = CRGB::White;
currentPalette[4] = CRGB::White;
currentPalette[8] = CRGB::White;
currentPalette[12] = CRGB::White;

}

// This function sets up a palette of purple and green stripes.
void SetupPurpleAndGreenPalette()
{
CRGB purple = CHSV( HUE_PURPLE, 255, 255);
CRGB green = CHSV( HUE_GREEN, 255, 255);
CRGB black = CRGB::Black;

currentPalette = CRGBPalette16(
                               green,  green,  black,  black,
                               purple, purple, black,  black,
                               green,  green,  black,  black,
                               purple, purple, black,  black );

}

const TProgmemPalette16 myRedWhiteBluePalette_p PROGMEM =
{
CRGB::Red,
CRGB::Gray, // ‘white’ is too bright compared to red and blue
CRGB::Blue,
CRGB::Black,

CRGB::Red,
CRGB::Gray,
CRGB::Blue,
CRGB::Black,

CRGB::Red,
CRGB::Red,
CRGB::Gray,
CRGB::Gray,
CRGB::Blue,
CRGB::Blue,
CRGB::Black,
CRGB::Black

};

Two things I’ve noticed:
currentPalette = Heart;
Where is that palette supposed to come from? I changed that to one of the preconfigured ones (HeatColors_p) so I could compile successfully.

While there is a “#define brightness 64” it’s only used for setup(). Inside FillLEDsFromPaletteColors you’re using a local variable brightness = 255;

This makes me wonder what you’re powering the 25 LEDs from. 25 WS2811/2812 at white and full brightness can take up to 1.5A!

I’d suggest putting these 3 lines inside your setup():

Serial.begin(57600); // set baud rate on serial console accordingly
Serial.println(“Starting up…”);
delay(500);

Open the serial monitor and watch. If the line “Starting up…” appears every time the leds seem to blink you’ve got a reset on the arduino. Probably due to power consumption of the 25 leds.

As always: Just a guess… :wink:

Sometimes the obvious hides very well from me:

static uint8_t startIndex = 0;
startIndex = startIndex + 1; /* motion speed */

You’re setting startIndex = 0 inside loop(). So the value won’t increase at all.

@Daniel_Cikic If startindex is defined as static, then it’s only defined once. That’s what I use to localize variables that need to be saved over multiple iterations.

That being said, if ji hun lee could post their code on http://gist.github.com, that would be a good thing.

@Andrew_Tuline Thanks for pointing out. While I understand what you said I still find it quite irritating seeing "= 0 " followed by “+ 1” in a loop… :smiley: But definitely something I should take a closer look at to clean up some code ^^

@Daniel_Cikic If it would make you feel better you could leave out the “= 0”. :wink:

@Daniel_Cikic Thanks for the comment!
I didn’t add the Heart palette to my code… Sorry
Also, I added the 3 lines to setup(), but the line “Starting up…” appears only once…

I still don’t know why ‘heart’ isn’t moving, though ColorPalette (ex.rainbowPalette) is moving provided by FastLED library

@ji_hun_lee Can you put your current code on http://gist.github.com and share the link? Thank you.

@Andrew_Tuline I just added my code on http://gist.github.com !

@marmil
I just added my code , Thank you!

@Lu_Jiang in your loop
static uint8_t startIndex;
startIndex = startIndex + 1; /* motion speed */
You define your variable every time hence it’s value is always 1.
Move the declaration outside the loop.
Hope this will help

@Yves_BAZIN You’re late, I’ve already made that mistake… :wink:

@Yves_BAZIN https://www.arduino.cc/reference/en/language/variables/variable-scope--qualifiers/static/

@Yves_BAZIN Thanks for your advice :slight_smile:
but… it doesn’t make any difference
i think i should do some more research :wink: