Add support for PWM controlled white LED strip
This commit is contained in:
parent
1a3cf20025
commit
11c37b7180
3 changed files with 36 additions and 12 deletions
31
Lighting.cpp
31
Lighting.cpp
|
@ -20,10 +20,13 @@ float Lighting::getIndexMultiplier(int now, int startTime, int endTime, bool swa
|
|||
}
|
||||
|
||||
float Lighting::getHeatIndex(int now) {
|
||||
float indexMultiplier = now >= _naturalLight->getSunset()
|
||||
return now >= _naturalLight->getSunset()
|
||||
? getIndexMultiplier(now, _naturalLight->getSunset(), _naturalLight->getAstronomicalTwilightEnd(), true)
|
||||
: getIndexMultiplier(now, _naturalLight->getAstronomicalTwilightBegin(), _naturalLight->getSunrise(), false);
|
||||
return MAX_HEAT_INDEX * indexMultiplier;
|
||||
}
|
||||
|
||||
float Lighting::getPaletteHeatIndex(int now){
|
||||
return MAX_HEAT_INDEX * getHeatIndex(now);
|
||||
}
|
||||
|
||||
float Lighting::getBrightness() {
|
||||
|
@ -31,14 +34,15 @@ float Lighting::getBrightness() {
|
|||
float multiplier = cloudCover * (_cloudCoverLimit / 100.0);
|
||||
if (_weather->getCondition() == WeatherCondition::Other)
|
||||
multiplier *= 2.0;
|
||||
return 255.0 - (multiplier * 255.0);
|
||||
return 1 - multiplier;
|
||||
}
|
||||
|
||||
void Lighting::update(int now) {
|
||||
_heatIndex = getHeatIndex(now);
|
||||
_brightness = getBrightness();
|
||||
float Lighting::getPaletteBrightness(){
|
||||
return getBrightness() * 255.0;
|
||||
}
|
||||
|
||||
CRGB colour = ColorFromPalette(_sunrise, _heatIndex, _brightness, LINEARBLEND);
|
||||
void Lighting::updateRGB(int now) {
|
||||
CRGB colour = ColorFromPalette(_sunrise, getPaletteHeatIndex(now), getPaletteBrightness(), LINEARBLEND);
|
||||
|
||||
if (_weather->getCondition() == WeatherCondition::Thunder && millis() >= _nextLightningFlash) {
|
||||
int flashes = random8(2, 8);
|
||||
|
@ -53,4 +57,17 @@ void Lighting::update(int now) {
|
|||
|
||||
fill_solid(_leds, _ledCount, colour);
|
||||
FastLED.show();
|
||||
}
|
||||
|
||||
void Lighting::updateWhite(){
|
||||
float brightness = (_heatIndex - 0.5) / 0.5;
|
||||
analogWrite(_whitePin, 1024 * brightness);
|
||||
}
|
||||
|
||||
void Lighting::update(int now) {
|
||||
_heatIndex = getHeatIndex(now);
|
||||
_brightness = getBrightness();
|
||||
|
||||
updateRGB(now);
|
||||
updateWhite();
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue