//test matrix layout

#include "FastLED.h"
 
// Matrix size
#define NUM_ROWS 7
#define NUM_COLS 6
#define NUM_LEDS NUM_ROWS * NUM_COLS
 
// LEDs pin
#define DATA_PIN 5     //led strip pin
#define LED_TYPE    WS2812B
#define COLOR_ORDER GRB
 
// LED brightness
#define BRIGHTNESS 180       //bright of leds from 0 to 255 (max) 
#define MAX_POWER_MILLIAMPS 900   //0.9А 
 
// Define the array of leds
CRGB leds[NUM_LEDS];

static const byte PlanarTable [] PROGMEM = {  // 7x6
  6,   7,  20,  21,  34,  35,
  5,   8,  19,  22,  33,  36,
  4,   9,  18,  23,  32,  37,
  3,  10,  17,  24,  31,  38,
  2,  11,  16,  25,  30,  39,
  1,  12,  15,  26,  29,  40,
  0,  13,  14,  27,  28,  41
};

void setup() {
  FastLED.addLeds<LED_TYPE, DATA_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
  FastLED.setMaxPowerInVoltsAndMilliamps(5, MAX_POWER_MILLIAMPS);
  FastLED.setBrightness(BRIGHTNESS);
}
 
uint8_t XY(byte x, byte y) {     // calculate index in leds from XY coordinates for planar mapping
  uint16_t ledsindex = pgm_read_byte (PlanarTable+y*NUM_COLS+x);
  return (ledsindex);
}

void fire2021 (){
 int  a = millis();
 int  a1 = a/3;
  for (byte j = 0; j < NUM_ROWS; j++) { 
    for (byte i = 0; i < NUM_COLS; i++) {
      byte ledsindex = XY( i, ((NUM_ROWS-1)-j));
      leds[ledsindex] = HeatColor(qsub8 (inoise8 (i * 60, j * 60+a, a1),  
      abs8(j - (NUM_ROWS-1)) * 255 / (NUM_ROWS+4)));
    }
  }
 delay (2);
}

void testlayout(){
  static byte index = 0;
  fadeToBlackBy(leds, NUM_LEDS, 10);
  leds [index].setHue(sin8((index = ++index%(NUM_LEDS))*255/(NUM_LEDS-1)+millis()/16));
  delay (40);
}


void loop() {
  // testlayout();
  fire2021 ();
  FastLED.show();
}