// For: https://forum.arduino.cc/t/fastled-help-with-splitting-a-strip-into-segments/1035740
// 4 * 8 leds is 32, but the sketch says 36 led ?
#include <FastLED.h>
#define LED_PIN 2
#define COLOR_ORDER GRB
#define CHIPSET WS2812B
#define NUM_LEDS 36 //LEDS on strip
#define ENGINE_1 8
#define ENGINE_2 8
///////Engine 1///////
#define EngineSize1 8
#define EngineStart1 0
#define EngineEnd1 8
///////Engine 2///////
#define EngineSize2 8
#define EngineStart2 8
#define EngineEnd2 16
///////Engine 3///////
#define EngineSize3 8
#define EngineStart3 16
#define EngineEnd3 24
///////Engine 4///////
#define EngineSize4 8
#define EngineStart4 24
#define EngineEnd4 32
#define BRIGHTNESS 255
#define FRAMES_PER_SECOND 100
bool gReverseDirection = false;
CRGB leds[NUM_LEDS];
CRGBPalette16 gPal;
void setup() {
delay(300); // sanity delay
FastLED.addLeds<CHIPSET, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
FastLED.setBrightness( BRIGHTNESS );
gPal = CRGBPalette16( CRGB::Black, CRGB::Red, CRGB::Yellow, CRGB::OrangeRed );
FastLED.show(); // display this frame
}
void loop()
{
// Add entropy to random number generator; we use a lot of it.
random16_add_entropy( esp_random()); // <<< use random() for ardunino esp_random() for ESP32
//ENGINE(EngineSize1,EngineStart1,EngineEnd1);
//ENGINE(EngineSize2,EngineStart2,EngineEnd2);
//ENGINE(EngineSize3,EngineStart3,EngineEnd3);
ENGINE(EngineSize4,EngineStart4,EngineEnd4);
FastLED.show(); // display this frame
FastLED.delay(1000 / FRAMES_PER_SECOND);
}
// COOLING: How much does the air cool as it rises?
// Less cooling = taller flames. More cooling = shorter flames.
// Default 55, suggested range 20-100
#define COOLING 20
// SPARKING: What chance (out of 255) is there that a new spark will be lit?
// Higher chance = more roaring fire. Lower chance = more flickery fire.
// Default 120, suggested range 50-200.
#define SPARKING 200
///////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////
void ENGINE(int EngineSize, int EngineStart, int EngineEnd)
{
// Array of temperature readings at each simulation cell
static uint8_t heat[8];
// Step 1. Cool down every cell a little
for( int i = EngineStart; i < EngineEnd; i++) {
heat[i] = qsub8( heat[i], random8(0, ((COOLING * 10) / EngineSize) + 2));
}
// Step 2. Heat from each cell drifts 'up' and diffuses a little
for( int k= EngineEnd - 1; k >= EngineStart; k--) {
heat[k] = (heat[k - 1] + heat[k - 2] + heat[k - 2] ) / 3;
}
// Step 3. Randomly ignite new 'sparks' of heat near the bottom
if( random8() < SPARKING ) {
int y = random8(EngineStart,EngineEnd);
heat[y] = qadd8( heat[y], random8(160,255) );
}
// Step 4. Map from heat cells to LED colors
for( int j = EngineStart; j < EngineEnd; j++) {
// Scale the heat value from 0-255 down to 0-240
// for best results with color palettes.
uint8_t colorindex = scale8( heat[j], 240);
CRGB color = ColorFromPalette( gPal, colorindex);
int pixelnumber;
if( gReverseDirection ) { //if( gReverseDirection ) { if( random(0,1) ) { //
pixelnumber = (NUM_LEDS-1) - j;
} else {
pixelnumber = j;
}
leds[pixelnumber] = color;
}
}
///////////////////////////////////////////////////////////////////////////////////////////