https://www.youtube.com/watch?v=o6_UYb6I4x4
create led matrix/grid effects
https://github.com/TylerTimoJ/LMCS2
#include <FastLED.h> #include <Wire.h> #include <VL53L1X.h> VL53L1X sensor; #define LED_PIN 15 #define COLOR_ORDER GRB #define CHIPSET WS2812 #define NUM_LEDS (kMatrixWidth * kMatrixHeight) #define FRAMES_PER_SECOND 60 ////////////////////////////////////////////////////// const uint8_t kMatrixWidth = 20; const uint8_t kMatrixHeight = 10; const bool kMatrixSerpentineLayout = true; ////////////////// int BRIGHTNESS = 5; ////////////////////////////////////////////////// bool gReverseDirection = false; CRGB leds[NUM_LEDS]; void setup() { Serial.begin(115200); Serial.println("*** Inicialization"); /////////////////////////////////////////////// delay(3000); // sanity delay FastLED.addLeds<CHIPSET, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS); FastLED.setBrightness( BRIGHTNESS ); Wire.begin(); Wire.setClock(400000); // use 400 kHz I2C sensor.setTimeout(500); while (!sensor.init()) { Serial.println("Failed to detect and initialize sensor!"); delay(100); } Serial.println("INIT"); sensor.setDistanceMode(VL53L1X::Long); sensor.setMeasurementTimingBudget(33000); // Start continuous readings at a rate of one measurement every 50 ms (the // inter-measurement period). This period should be at least as long as the // timing budget. sensor.startContinuous(33); } /////////////////////////////////// end setup int COOLING = 90; //this is hack void loop() { Fire2012(); FastLED.show(); // display this frame FastLED.delay(1000 / FRAMES_PER_SECOND); //TODO: change thi time measure auto ss = sensor.read(); static int s = 0; Serial.print(ss); if (sensor.timeoutOccurred()) { Serial.print(" TIMEOUT"); } else { COOLING = ss/10; // burimas cia Serial.print(","); Serial.print(COOLING); //FastLED.delay(ss /10); } int aaa = analogRead(A0); if (aaa<690) { BRIGHTNESS --; FastLED.setBrightness(BRIGHTNESS); } if (aaa>720) { BRIGHTNESS ++; FastLED.setBrightness(BRIGHTNESS); } if (BRIGHTNESS < 1) BRIGHTNESS = 1; if (BRIGHTNESS >= 255) BRIGHTNESS = 255; FastLED.setBrightness( BRIGHTNESS ); Serial.print(","); Serial.print(aaa); Serial.print(","); Serial.print(BRIGHTNESS); Serial.println(); } void Fire2012() { int SPARKING = 100; // Array of temperature readings at each simulation cell static byte heat[kMatrixWidth] [kMatrixHeight]; // Step 1. Cool down every cell a little for (int n = 0; n< kMatrixHeight; n++) { for ( int i = 0; i < kMatrixWidth; i++) { heat[i][n] = qsub8( heat[i][n], random8(0, ((COOLING * 10) / (kMatrixWidth)) + 2)); } // Step 2. for ( int k = (kMatrixWidth- 1); k >= 2; k--) { heat[k][n] = (heat[k - 1][n] + heat[k - 2][n] + heat[k - 2][n] ) / 3; } // Step 3. if ( random8() < SPARKING ) { int y = random8(3); heat[y][n] = qadd8( heat[y][n], random8(160, 255) ); } } // Step 4. Map from heat cells to LED colors for ( int i= 0; i < kMatrixWidth; i++) { for (int j = 0; j < kMatrixHeight; j++) { CRGB color = HeatColor(heat[i][j]); leds[XY(i, j)] = color; } } } ///////////// uint16_t XY( uint8_t x, uint8_t y) { uint16_t i; if ( kMatrixSerpentineLayout == false) { i = (y * kMatrixWidth) + x; } if ( kMatrixSerpentineLayout == true) { if ( y & 0x01) { // Odd rows run backwards uint8_t reverseX = (kMatrixWidth - 1) - x; i = (y * kMatrixWidth) + reverseX; } else { // Even rows run forwards i = (y * kMatrixWidth) + x; } } return i; }/////