Last active
April 13, 2021 18:16
-
-
Save todbot/c22a071d6e0bc711d8746d283c1aac99 to your computer and use it in GitHub Desktop.
Tiny fire simulation for QT Py or any FastLED-supporting board
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// modeled after https://github.com/todbot/qtpy-tricks#fire-simulation-on-external-neopixel-strip | |
// must use latest FastLED checkout from https://github.com/FastLED/FastLED | |
// as FastLED 3.3.3 doesn't have QT Py support | |
#include "FastLED.h" | |
#define LED_PIN 0 | |
#define NUM_LEDS 8 | |
CRGB leds[NUM_LEDS]; | |
void setup() { | |
FastLED.addLeds<WS2812, LED_PIN,GRB>(leds, NUM_LEDS); | |
FastLED.setBrightness( 50 ); // out of 255 | |
} | |
void loop() { | |
// dim all LEDs by (30,30,30) | |
for(int i=0; i<NUM_LEDS; i++) { | |
leds[i] -= CRGB(30,30,30); | |
} | |
// shift LEDs down by one | |
for(int i=NUM_LEDS-1; i>0; i--) { | |
leds[i] = leds[i-1]; | |
} | |
// set first LED to random fire color | |
leds[0] = CRGB( random(150,255), random(50,100), 0); | |
FastLED.show(); | |
delay(100); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you! I'll test it out.
I appreciate it!