Skip to content

Instantly share code, notes, and snippets.

@atuline
Last active May 10, 2022 00:34
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save atuline/300414b26e54b2d8ef6e5d2af3c2458f to your computer and use it in GitHub Desktop.
Save atuline/300414b26e54b2d8ef6e5d2af3c2458f to your computer and use it in GitHub Desktop.
/* 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."
#endif
#define LED_PIN 12
#define CLK_PIN 11
#define BRIGHTNESS 128
#define LED_TYPE APA102 // Only use the LED_PIN for WS2812's
#define COLOR_ORDER BGR
#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() {
Serial.begin(57600);
delay(3000);
// LEDS.addLeds<LED_TYPE,LED_PIN,COLOR_ORDER>(leds,NUM_LEDS);
LEDS.addLeds<LED_TYPE,LED_PIN,CLK_PIN, COLOR_ORDER>(leds,NUM_LEDS);
LEDS.setBrightness(BRIGHTNESS);
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 . . .
LEDS.show(); // 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