Put in hack to reduce flickering issue.

This commit is contained in:
Robert Marshall 2018-12-09 21:02:46 +00:00
parent c0c4e75db0
commit ccbbf6e4c1
3 changed files with 23 additions and 16 deletions

View file

@ -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(){

View file

@ -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);

View file

@ -1,5 +1,4 @@
#include <FastLED.h>
#include<FastLED.h>
#include <time.h>
#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(){