diff --git a/Lighting.cpp b/Lighting.cpp index 6aefd2c..9f857c0 100644 --- a/Lighting.cpp +++ b/Lighting.cpp @@ -42,21 +42,27 @@ float Lighting::getPaletteBrightness(){ } void Lighting::updateRGB(int now) { - CRGB colour = ColorFromPalette(_sunrise, getPaletteHeatIndex(now), getPaletteBrightness(), LINEARBLEND); + byte heatIndex = getPaletteHeatIndex(now); + byte brightness = getPaletteBrightness(); + if (heatIndex != _lastHeatIndex || brightness!=_lastBrightness) { + CRGB colour = ColorFromPalette(_sunrise, heatIndex, brightness, LINEARBLEND); - if (_weather->getCondition() == WeatherCondition::Thunder && millis() >= _nextLightningFlash) { - int flashes = random8(2, 8); - for (int i = 0; i < flashes; i++) { - FastLED.showColor(CRGB::White); - delay(random8(10, 20)); - FastLED.showColor(colour); - delay(random8(40, 80)); + if (_weather->getCondition() == WeatherCondition::Thunder && millis() >= _nextLightningFlash) { + int flashes = random8(2, 8); + for (int i = 0; i < flashes; i++) { + FastLED.showColor(CRGB::White); + delay(random8(10, 20)); + FastLED.showColor(colour); + delay(random8(40, 80)); + } + _nextLightningFlash = millis() + (random8(1, 60) * 1000); } - _nextLightningFlash = millis() + (random8(1, 60) * 1000); - } - fill_solid(_leds, _ledCount, colour); - FastLED.show(); + fill_solid(_leds, _ledCount, colour); + FastLED.show(); + } + _lastHeatIndex = heatIndex; + _lastBrightness = brightness; } void Lighting::updateWhite(){ diff --git a/Lighting.h b/Lighting.h index 9818948..4851a6a 100644 --- a/Lighting.h +++ b/Lighting.h @@ -21,6 +21,7 @@ class Lighting { long _nextLightningFlash = 0; float _heatIndex; float _brightness; + byte _lastHeatIndex, _lastBrightness; float _currentHeatIndex(); float getIndexMultiplier(int now, int startTime, int endTime, bool swap); diff --git a/monitor.ino b/monitor.ino index 51595ed..3652dc7 100644 --- a/monitor.ino +++ b/monitor.ino @@ -1,5 +1,4 @@ - -#include +#include #include #include "Networking.h" @@ -18,7 +17,7 @@ #define RGB_PIN D3 #define WHITE_PIN D2 -#define LED_COUNT 39 +#define LED_COUNT 41 #define LATITUDE "20.548103" #define LONGITUDE "96.916835" #define TIMEZONE_OFFSET 30600 // 8.5 hours in seconds @@ -65,10 +64,11 @@ void doLighting() { } EVERY_N_SECONDS(1) { - _lighting.update(time(nullptr)); publishFloat(LIGHT_INDEX_TOPIC, _lighting.getCurrentHeatIndex()); publishFloat(BRIGHTNESS_TOPIC, _lighting.getCurrentBrightness()); } + + _lighting.update(time(nullptr)); } void publishReadings(){