#include "FastLED.h"
#include <EEPROMex.h>
#define NUM_LEDS 8
CRGB leds[NUM_LEDS];
#define PIN 3
#define BTN_SPEED 4
#define BTN_BRIGHT 2
uint8_t speed[] = {30, 70, 100};
uint8_t bright[] = {100};
uint8_t buttonStateSpeed;
uint8_t buttonStateBright;
uint8_t defaultSpeed = 30;
uint8_t defaultBright = 100;
uint8_t lastButtonStateSpeed = HIGH;
uint8_t lastButtonStateBright = HIGH;
unsigned long lastDebounceTime = 0;
unsigned long debounceDelay = 40;
void setup() {
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, HIGH);
pinMode(BTN_SPEED, INPUT);
digitalWrite(BTN_SPEED, HIGH);
pinMode(BTN_BRIGHT, INPUT);
digitalWrite(BTN_BRIGHT, HIGH);
FastLED.addLeds<WS2812B, PIN, GRB>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
}
void loop() {
Fire(15, 40, 60);
}
void showStrip() {
FastLED.show();
}
void setPixel(int Pixel, byte red, byte green, byte blue) {
leds[Pixel].r = red;
leds[Pixel].g = green;
leds[Pixel].b = blue;
}
void setAll(byte red, byte green, byte blue) {
for (int i = 0; i < NUM_LEDS; i++ ) {
setPixel(i, red, green, blue);
}
showStrip();
}
void Fire(int Cooling, int Sparking, int SpeedDelay) {
static byte heat[NUM_LEDS];
int cooldown;
// Step 1. Cool down every cell a little
for ( int i = 0; i < NUM_LEDS; i++) {
cooldown = random(0, ((Cooling * 10) / NUM_LEDS) + 2);
if (cooldown > heat[i]) {
heat[i] = 0;
} else {
heat[i] = heat[i] - cooldown;
}
}
// 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' near the bottom
if ( random(255) < Sparking ) {
int y = random(7);
//heat[y] = heat[y] + random(160, 255);
heat[y] = random(160,255);
}
// Step 4. Convert heat to LED colors
for ( int j = 0; j < NUM_LEDS; j++) {
setPixelHeatColor(j, heat[j] );
}
showStrip();
delay(SpeedDelay);
}
void setPixelHeatColor (int Pixel, byte temperature) {
// Scale 'heat' down from 0-255 to 0-191
byte t192 = round((temperature / 255.0) * 191);
// calculate ramp up from
byte heatramp = t192 & 0x3F; // 0..63
heatramp <<= 2; // scale up to 0..252
//dimm to the desired brightness
float mod = 100 / 100.0;
// figure out which third of the spectrum we're in:
if ( t192 > 0x80) { // hottest
setPixel(Pixel, 255 * mod, 255 * mod, heatramp * mod);
} else if ( t192 > 0x40 ) { // middle
setPixel(Pixel, 255 * mod, heatramp * mod, 0);
} else { // coolest
setPixel(Pixel, heatramp * mod, 0, 0);
}
}