#include <FastLED.h>
#define HEIGHT 11
#define WIDTH 64
#define NUM_LEDS WIDTH * HEIGHT
#define MATRIX_TYPE 1
// LEDs pin
#define DATA_PIN 2
// LED brightness
#define BRIGHTNESS 255
// Define the array of leds
CRGB leds[NUM_LEDS];
CRGB FirePalColor(uint8_t temp, uint8_t col) {
CRGB TEMP_COL = CRGB(0,0,0);
uint8_t colIndex[3] {(col >> 1), // 1 channel RRGGBB
((((col + 3) >> 1)) % 3), // 2 channel GBBRRG
((2 - col) % 3) // 3 channel BGRBGR
};
uint8_t t192 = scale8_video( temp, 191);
// calculate a value that ramps up from
// zero to 255 in each 'third' of the scale.
uint8_t heatramp = t192 & 0x3F; // 0..63
heatramp <<= 2; // scale up to 0..252
if ( t192 & 0x80) { //to white
TEMP_COL[colIndex[0]] = 255;
TEMP_COL[colIndex[1]] = 255;
TEMP_COL[colIndex[2]] = heatramp;
} else if ( t192 & 0x40 ) { //2 channels
TEMP_COL[colIndex[0]] = 255;
TEMP_COL[colIndex[1]] = heatramp;
TEMP_COL[colIndex[2]] = 0;
} else {//1 channel
TEMP_COL[colIndex[0]] = heatramp;
TEMP_COL[colIndex[1]] = 0;
TEMP_COL[colIndex[2]] = 0;
}
return TEMP_COL;
}
void setup() {
// put your setup code here, to run once:
FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
FastLED.setBrightness(BRIGHTNESS);
Serial.begin(9600);
}
uint16_t a;
void loop() {
FastLED.clear();
a += 8;
for (uint8_t y = 0; y < HEIGHT; y+=2) {
for (uint8_t x = 0; x < WIDTH; x++) {
leds[XY(x, y)] = FirePalColor(constrain(inoise8(x * 32 - a, y * 128) - (x << 1), 0 , 255), y >> 1);
}
}
FastLED.show();
}
uint16_t XY (uint8_t x, uint8_t y) {
return (y * WIDTH + x);
}