#include <FastLED.h>
#define TIMING 0
#define LED_PIN 3
#define NUM_LEDS 1630
#define LED_TYPE WS2812
#define COLOR_ORDER GRB
CRGB leds[NUM_LEDS];
const uint8_t led_count[] = {160, 145, 142, 135, 125, 118, 110, 102, 95, 86, 78, 70, 62, 53, 45, 37, 29, 21, 12, 4, 1};
#define NUM_RINGS (sizeof(led_count) / sizeof(led_count[0]))
#define FIRE_WIDTH 64
#define FIRE_HEIGHT NUM_RINGS
static uint8_t heat[FIRE_WIDTH][FIRE_HEIGHT];
CRGBPalette256 currentPalette;
void setup() {
Serial.begin(115200);
FastLED.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS);
uint8_t i = 0;
do {
currentPalette[i] = HeatColor(i);
} while (++i);
}
void loop() {
unsigned long t1 = micros();
Fire2012(random8() / 2 + 128);
unsigned long t2 = micros();
CRGB *led = leds;
uint8_t ring = 0;
// map the modified Fire2012() onto the rings
do {
uint8_t count = led_count[ring];
uint16_t td = FIRE_WIDTH * 255 / count;
uint16_t t = 0;
for (uint8_t i = 0; i < count ; i++) {
uint8_t h = heat[t >> 8][FIRE_HEIGHT - 1 - ring];
*led++ = currentPalette[h];
t += td;
}
} while (++ring < NUM_RINGS);
unsigned long t3 = micros();
FastLED.show();
if (TIMING) {
static unsigned long t2_sum, t3_sum;
t2_sum += t2 - t1;
t3_sum += t3 - t2;
static byte frame;
if (!(++frame % 64)) {
Serial.print(F("fire "));
Serial.print(t2_sum / 64);
Serial.print(F("us\tmap "));
Serial.print(t3_sum / 64);
Serial.print(F(" us\t"));
Serial.println(FastLED.getFPS());
t2_sum = t3_sum = 0;
}
}
}
void Fire2012(uint8_t activity) {
for (uint8_t h = 0; h < FIRE_WIDTH; h++) {
// Step 1. Cool down every cell a little
for( uint8_t i = 1; i < FIRE_HEIGHT - 1; i++) {
heat[h][i] = qsub8( heat[h][i], random8(32));
}
// Step 2. Heat from each cell drifts 'up' and diffuses a little
for( uint8_t k = FIRE_HEIGHT - 1; k >= 1; k--) {
uint8_t hleft = (h + FIRE_WIDTH - 1) % FIRE_WIDTH;
uint8_t hright = (h+1) % FIRE_WIDTH;
heat[h][k] = (heat[h][k]
+ heat[hleft][k - 1]
+ heat[h][k - 1]
+ heat[hright][k - 1] ) / 4;
}
if( random8() < activity ) {
heat[h][0] = qadd8( heat[h][0], random8(64));
} else {
heat[h][0] = qsub8( heat[h][0], random8(64));
}
}
}
mega:SCL
mega:SDA
mega:AREF
mega:GND.1
mega:13
mega:12
mega:11
mega:10
mega:9
mega:8
mega:7
mega:6
mega:5
mega:4
mega:3
mega:2
mega:1
mega:0
mega:14
mega:15
mega:16
mega:17
mega:18
mega:19
mega:20
mega:21
mega:5V.1
mega:5V.2
mega:22
mega:23
mega:24
mega:25
mega:26
mega:27
mega:28
mega:29
mega:30
mega:31
mega:32
mega:33
mega:34
mega:35
mega:36
mega:37
mega:38
mega:39
mega:40
mega:41
mega:42
mega:43
mega:44
mega:45
mega:46
mega:47
mega:48
mega:49
mega:50
mega:51
mega:52
mega:53
mega:GND.4
mega:GND.5
mega:IOREF
mega:RESET
mega:3.3V
mega:5V
mega:GND.2
mega:GND.3
mega:VIN
mega:A0
mega:A1
mega:A2
mega:A3
mega:A4
mega:A5
mega:A6
mega:A7
mega:A8
mega:A9
mega:A10
mega:A11
mega:A12
mega:A13
mega:A14
mega:A15
pixel1:VDD
pixel1:DOUT
pixel1:VSS
pixel1:DIN
ring4:GND
ring4:VCC
ring4:DIN
ring4:DOUT
ring12:GND
ring12:VCC
ring12:DIN
ring12:DOUT
ring21:GND
ring21:VCC
ring21:DIN
ring21:DOUT
ring29:GND
ring29:VCC
ring29:DIN
ring29:DOUT
ring37:GND
ring37:VCC
ring37:DIN
ring37:DOUT
ring45:GND
ring45:VCC
ring45:DIN
ring45:DOUT
ring53:GND
ring53:VCC
ring53:DIN
ring53:DOUT
ring62:GND
ring62:VCC
ring62:DIN
ring62:DOUT
ring70:GND
ring70:VCC
ring70:DIN
ring70:DOUT
ring78:GND
ring78:VCC
ring78:DIN
ring78:DOUT
ring86:GND
ring86:VCC
ring86:DIN
ring86:DOUT
ring95:GND
ring95:VCC
ring95:DIN
ring95:DOUT
ring102:GND
ring102:VCC
ring102:DIN
ring102:DOUT
ring110:GND
ring110:VCC
ring110:DIN
ring110:DOUT
ring118:GND
ring118:VCC
ring118:DIN
ring118:DOUT
ring125:GND
ring125:VCC
ring125:DIN
ring125:DOUT
ring135:GND
ring135:VCC
ring135:DIN
ring135:DOUT
ring142:GND
ring142:VCC
ring142:DIN
ring142:DOUT
ring145:GND
ring145:VCC
ring145:DIN
ring145:DOUT
ring160:GND
ring160:VCC
ring160:DIN
ring160:DOUT