arduino:led_matrix
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| arduino:led_matrix [2019/04/04 19:32] – aistis | arduino:led_matrix [2019/04/04 19:32] (current) – aistis | ||
|---|---|---|---|
| Line 5: | Line 5: | ||
| https:// | https:// | ||
| - | < | + | < |
| - | JPEGDecoder | + | #include < |
| + | #include < | ||
| + | #include < | ||
| + | |||
| + | |||
| + | VL53L1X sensor; | ||
| + | |||
| + | # | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | ////////////////////////////////////////////////////// | ||
| + | const uint8_t kMatrixWidth | ||
| + | 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(" | ||
| + | /////////////////////////////////////////////// | ||
| + | delay(3000); | ||
| + | FastLED.addLeds< | ||
| + | FastLED.setBrightness( BRIGHTNESS ); | ||
| + | |||
| + | |||
| + | Wire.begin(); | ||
| + | Wire.setClock(400000); | ||
| + | sensor.setTimeout(500); | ||
| + | while (!sensor.init()) | ||
| + | { | ||
| + | Serial.println(" | ||
| + | delay(100); | ||
| + | } | ||
| + | Serial.println(" | ||
| + | |||
| + | sensor.setDistanceMode(VL53L1X:: | ||
| + | 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); | ||
| + | } | ||
| + | /////////////////////////////////// | ||
| + | |||
| + | int COOLING = 90; //this is hack | ||
| + | |||
| + | void loop() | ||
| + | { | ||
| + | | ||
| + | | ||
| + | |||
| + | | ||
| + | |||
| + | |||
| + | auto ss = sensor.read(); | ||
| + | static int s = 0; | ||
| + | Serial.print(ss); | ||
| + | if (sensor.timeoutOccurred()) { Serial.print(" | ||
| + | else { | ||
| + | COOLING = ss/10; // burimas cia | ||
| + | Serial.print("," | ||
| + | // | ||
| + | } | ||
| + | |||
| + | int aaa = analogRead(A0); | ||
| + | if (aaa< | ||
| + | if (aaa> | ||
| + | if (BRIGHTNESS < 1) BRIGHTNESS = 1; | ||
| + | if (BRIGHTNESS >= 255) BRIGHTNESS = 255; | ||
| + | | ||
| + | Serial.print("," | ||
| + | Serial.print("," | ||
| + | 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; | ||
| + | { | ||
| + | |||
| + | for ( int i = 0; i < kMatrixWidth; | ||
| + | | ||
| + | | ||
| + | } | ||
| + | |||
| + | // 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); | ||
| + | | ||
| + | } | ||
| + | } | ||
| + | |||
| + | // Step 4. Map from heat cells to LED colors | ||
| + | |||
| + | for ( int i= 0; i < kMatrixWidth; | ||
| + | for (int j = 0; j < kMatrixHeight; | ||
| + | |||
| + | 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 | ||
| + | | ||
| + | i = (y * kMatrixWidth) + reverseX; | ||
| + | } else { | ||
| + | // Even rows run forwards | ||
| + | i = (y * kMatrixWidth) + x; | ||
| + | } | ||
| + | } | ||
| + | |||
| + | return i; | ||
| + | |||
| + | | ||
| </ | </ | ||
arduino/led_matrix.1554395552.txt.gz · Last modified: by aistis
