Wondering if anyone has run across code that allows for a "twinkling" effect (similar to Mark Kriegsman's - MapTwinkle) that I can assign to led positions in an array. I thought I could use something similar to his code, but reading more about fill_solid has be worried it is not intended for spaces between leds. I was hoping to get that twinkle effect on an array. Specifically only these leds in my sketch would twinkle.
int orange[11] = {0,3,6,9,12,15,18,21,24,27,30};
Not sure if it is important or not, but I do plan to have the other led positions running a different function.
This is Mark's code I was looking at for inspiration
#include "FastLED.h"
// MapTwinkle
// Designed to illuminate a 'map' of pixels, each of which randomly
// sometimes twinkles brighter and then back down to it's base color again.
//
// Parameters include: background color, peak twinkle color, and speed
// of brightening and dimming.
//
// Mark Kriegsman, August 2015
#define LED_PIN 2
#define LED_TYPE WS2812B
#define COLOR_ORDER GRB
#define NUM_LEDS 90
CRGB leds[NUM_LEDS];
#define MASTER_BRIGHTNESS 100
// Base background color
#define BASE_COLOR CRGB(22,0,22)
// Peak color to twinkle up to
#define PEAK_COLOR CRGB(84,0,84)
// Currently set to brighten up a bit faster than it dims down,
// but this can be adjusted.
// Amount to increment the color by each loop as it gets brighter:
#define DELTA_COLOR_UP CRGB(4,0,4)
// Amount to decrement the color by each loop as it gets dimmer:
#define DELTA_COLOR_DOWN CRGB(1,0,1)
// Chance of each pixel starting to brighten up.
// 1 or 2 = a few brightening pixels at a time.
// 10 = lots of pixels brightening at a time.
#define CHANCE_OF_TWINKLE 4
void setup() {
delay(3000);
FastLED.addLeds<LED_TYPE,LED_PIN,COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
FastLED.setBrightness(MASTER_BRIGHTNESS);
InitPixelStates();
}
void loop()
{
TwinkleMapPixels();
FastLED.show();
FastLED.delay(30);
}
enum { SteadyDim, GettingBrighter, GettingDimmerAgain };
uint8_t PixelState[NUM_LEDS];
void InitPixelStates()
{
memset( PixelState, sizeof(PixelState), SteadyDim); // initialize all the pixels to SteadyDim.
fill_solid( leds, NUM_LEDS, BASE_COLOR);
}
void TwinkleMapPixels()
{
for( uint16_t i = 0; i < NUM_LEDS; i++) {
if( PixelState[i] == SteadyDim) {
// this pixels is currently: SteadyDim
// so we randomly consider making it start getting brighter
if( random8() < CHANCE_OF_TWINKLE) {
PixelState[i] = GettingBrighter;
}
} else if( PixelState[i] == GettingBrighter ) {
// this pixels is currently: GettingBrighter
// so if it's at peak color, switch it to getting dimmer again
if( leds[i] >= PEAK_COLOR ) {
PixelState[i] = GettingDimmerAgain;
} else {
// otherwise, just keep brightening it:
leds[i] += DELTA_COLOR_UP;
}
} else { // getting dimmer again
// this pixels is currently: GettingDimmerAgain
// so if it's back to base color, switch it to steady dim
if( leds[i] <= BASE_COLOR ) {
leds[i] = BASE_COLOR; // reset to exact base color, in case we overshot
PixelState[i] = SteadyDim;
} else {
// otherwise, just keep dimming it down:
leds[i] -= DELTA_COLOR_DOWN;
}
}
}
}
Any suggestions would be appreciated by this rookie.