Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Perlin noise fire procedure
- //16x16 rgb led matrix demo
- //Yaroslaw Turbin, 22.06.2020
- //https://vk.com/ldirko
- //https://www.reddit.com/user/ldirko/
- //https://www.reddit.com/r/FastLED/comments/hgu16i/my_fire_effect_implementation_based_on_perlin/
- //idea in make perlin noise with time offset X and Z coord
- //this automatic scroll fire pattern
- //and distort fire noise.
- //then substract Y based coodrd value to shift
- //fire color (not brightness) in palette.
- //this fadeout color from bottom matrix to up.
- //this need some palette tweak for good looking fire color
- #include "FastLED.h"
- // Matrix size
- #define NUM_ROWS 2
- #define NUM_COLS 2
- #define NUM_LEDS NUM_ROWS * NUM_COLS
- // LEDs pin
- #define DATA_PIN 3
- // LED brightness
- #define BRIGHTNESS 255
- // Define the array of leds
- CRGB leds[NUM_LEDS];
- DEFINE_GRADIENT_PALETTE( firepal ) { // define fire palette
- 0, 0, 0, 0, //black
- 32, 255, 0, 0, // red
- 190, 255, 255, 0, //yellow
- 255, 255, 255, 255 // white
- };
- CRGBPalette16 myPal = firepal;
- void setup() {
- FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
- FastLED.setBrightness(BRIGHTNESS);
- }
- void loop() {
- EVERY_N_MILLISECONDS(20) {fire(); }
- FastLED.show();
- }
- void fire (){
- static int a = 0;
- for (int i = 0; i < NUM_COLS; i++) {
- for (int j = 0; j < NUM_ROWS; j++) {
- leds[XY(i,j)] = ColorFromPalette (myPal, inoise8 (i * 80 , j * 80+ a , a /3), BRIGHTNESS);
- }
- }
- a+=20;
- }
- uint8_t XY (uint8_t x, uint8_t y) { return (y * NUM_COLS + x);} //simple function to find led number in led matrix,
- //change this to your routine
- //or generate XY function for your matrix there:
- //https://macetech.github.io/FastLED-XY-Map-Generator/
Add Comment
Please, Sign In to add comment