// https://www.reddit.com/r/FastLED/comments/19fjpop/multiple_separate_flames_using/

#include <FastLED.h>

#define BRIGHTNESS 255
#define NUM_LEDS 60
CRGB leds[NUM_LEDS];

bool gReverseDirection = true;

// store a palette in PROGMEM
FL_PROGMEM extern const TProgmemPalette16 RainbowHalfStripeColors_p = {
  0xFF0000, 0x7F0000, 0xAB5500, 0x552A00,
  0xABAB00, 0x555500, 0x00FF00, 0x007F00,
  0x00AB55, 0x00552A, 0x0000FF, 0x00007F,
  0x5500AB, 0x2A0055, 0xAB0055, 0x55002A
};

// A list of the palettes
const TProgmemPalette16 * palettes[] = {
  &HeatColors_p, &RainbowHalfStripeColors_p, &PartyColors_p,
};
const size_t palettes_count = sizeof(palettes) / sizeof(*palettes);


void setup() {
  FastLED.addLeds<WS2812B, PB0, GRB>(leds, NUM_LEDS);
  FastLED.addLeds<WS2812B, PB1, GRB>(leds, NUM_LEDS);
  FastLED.addLeds<WS2812B, PB2, GRB>(leds, NUM_LEDS);
}

void loop() {
  random16_add_entropy(random());
  Fire2012();

  for (auto strip = 0; strip < 3; strip++) {
    Fire2012MapPalette(palettes[strip]);
    FastLED[strip].showLeds(BRIGHTNESS);
  }

}

#define COOLING  55
#define SPARKING 120
// Array of temperature readings at each simulation cell
static uint8_t heat[NUM_LEDS];

void Fire2012() {
  // Step 1.  Cool down every cell a little
  for (int i = 0; i < NUM_LEDS; i++) {
    heat[i] = qsub8( heat[i],  random8(0, ((COOLING * 10) / NUM_LEDS) + 2));
  }

  // Step 2.  Heat from each cell drifts 'up' and diffuses a little
  for (int k = NUM_LEDS - 1; k >= 2; 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(7);
    heat[y] = qadd8(heat[y], random8(160, 255));
  }
}

void Fire2012MapPalette(TProgmemPalette16 * Pal) {
  // Step 4.  Map from heat cells to LED colors
  for (int j = 0; j < NUM_LEDS; 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(*Pal, colorindex);
    int pixelnumber;
    if (gReverseDirection)
      pixelnumber = (NUM_LEDS - 1) - j;
    else
      pixelnumber = j;
    leds[pixelnumber] = color;
  }
}
ATTINY8520PU