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
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
};