Skip to content

Instantly share code, notes, and snippets.

Last active Apr 24, 2018
What would you like to do?
/* Title: inoise8_fire.ino
* By: Andrew Tuline
* Date: January 2017
* This super short sketch displays fire thanks to FastLED's Perlin Noise function and Palettes.
* It needs some tweaking in order to work across a wide range of NUM_LED values, but looks pretty good at 60.
#include "FastLED.h"
#if FASTLED_VERSION < 3001000
#error "Requires FastLED 3.1 or later; check github for latest code."
#define LED_PIN 12
#define CLK_PIN 11
#define BRIGHTNESS 128
#define LED_TYPE APA102 // Only use the LED_PIN for WS2812's
#define NUM_LEDS 60
struct CRGB leds[NUM_LEDS];
uint32_t xscale = 20; // How far apart they are
uint32_t yscale = 3; // How fast they move
uint8_t index = 0;
CRGBPalette16 currentPalette(CRGB::Black);
void setup() {
currentPalette = CRGBPalette16(
CRGB::Black, CRGB::Black, CRGB::Black, CRGB::Maroon,
CRGB::DarkRed, CRGB::Red, CRGB::Red, CRGB::Red,
CRGB::DarkOrange,CRGB::Orange, CRGB::Orange, CRGB::Orange,
CRGB::Yellow, CRGB::Yellow, CRGB::Gray, CRGB::Gray);
} // setup()
void loop() {
inoise8_fire(); // I am the god of hell fire and I bring you . . .; // Display the LED's at every loop cycle.
} // loop()
void inoise8_fire() {
for(int i = 0; i < NUM_LEDS; i++) {
index = inoise8(i*xscale,millis()*yscale*NUM_LEDS/255); // X location is constant, but we move along the Y at the rate of millis()
leds[i] = ColorFromPalette(currentPalette, min(i*(index)>>6, 255), i*255/NUM_LEDS, LINEARBLEND); // With that value, look up the 8 bit colour palette value and assign it to the current LED.
} // The higher the value of i => the higher up the palette index (see palette definition).
// Also, the higher the value of i => the brighter the LED.
} // inoise8_fire()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment