Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <FastLED.h>
- #define CLOCK_PIN D2
- #define DATA_PIN D3
- #define COLOR_ORDER BGR
- #define CHIPSET APA102
- #define NUM_LEDS_X2 60
- #define NUM_LEDS 30
- #define BRIGHTNESS 50
- #define FRAMES_PER_SECOND 100
- bool gReverseDirection = false;
- CRGB leds[NUM_LEDS];
- void setup() {
- Serial.begin(115200);
- delay(3000); // sanity delay
- FastLED.addLeds<CHIPSET, DATA_PIN,CLOCK_PIN, COLOR_ORDER>(leds, NUM_LEDS_X2).setCorrection( TypicalLEDStrip );
- FastLED.setBrightness( BRIGHTNESS );
- }
- void loop()
- {
- // Add entropy to random number generator; we use a lot of it.
- // random16_add_entropy( random());
- Fire2012(); // run first half of simulation frame
- FastLED.show(); // display this frame
- FastLED.delay(1000 / FRAMES_PER_SECOND);
- }
- #define COOLING 55
- #define SPARKING 120
- void Fire2012()
- {
- // Array of temperature readings at each simulation cell
- static byte heat[NUM_LEDS];
- // Step 1. Cool down every cell a little
- for( int i = 0; i < NUM_LEDS; i++) {
- heat[i] = qsub8( heat[i], random8(0, ((COOLING * 10) / NUM_LEDS) + 2));
- }
- // 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' of heat near the bottom
- if( random8() < SPARKING ) {
- int y = random8(7);
- heat[y] = qadd8( heat[y], random8(160,255) );
- }
- // Step 4. Map from heat cells to LED colors
- for( int j = 0; j < NUM_LEDS; j++) {
- CRGB color = HeatColor( heat[j]);
- int pixelnumber=j;
- Serial.print("Pix ");
- Serial.println(pixelnumber);
- leds[pixelnumber] = color;
- pixelnumber = (NUM_LEDS_X2-1) - j;
- Serial.print("Pix ");
- Serial.println(pixelnumber);
- leds[pixelnumber] = color;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment