Add ability for PWM controlled RGB.
This commit is contained in:
parent
059ebad84e
commit
0e18b3371b
3 changed files with 71 additions and 18 deletions
28
Lighting.cpp
28
Lighting.cpp
|
@ -3,8 +3,7 @@
|
|||
|
||||
#define MAX_HEAT_INDEX 240.0
|
||||
|
||||
Lighting::Lighting(int ledCount, NaturalLight* naturalLight, Weather* weather, float cloudCoverLimit) {
|
||||
_ledCount = ledCount;
|
||||
Lighting::Lighting(NaturalLight* naturalLight, Weather* weather, float cloudCoverLimit) {
|
||||
_naturalLight = naturalLight;
|
||||
_weather = weather;
|
||||
_cloudCoverLimit = cloudCoverLimit;
|
||||
|
@ -41,6 +40,22 @@ float Lighting::getPaletteBrightness(){
|
|||
return getBrightness() * 255.0;
|
||||
}
|
||||
|
||||
int Lighting::byteToAnalogue(byte input){
|
||||
float fraction = input / 255.0;
|
||||
return fraction * 1024;
|
||||
}
|
||||
|
||||
void Lighting::outputColour(CRGB colour){
|
||||
if (_useStrip)
|
||||
FastLED.showColor(colour);
|
||||
|
||||
if (_usePWM){
|
||||
analogWrite(_rPin, byteToAnalogue(colour.r));
|
||||
analogWrite(_gPin, byteToAnalogue(colour.g));
|
||||
analogWrite(_bPin, byteToAnalogue(colour.b));
|
||||
}
|
||||
}
|
||||
|
||||
void Lighting::updateRGB(int now) {
|
||||
byte heatIndex = getPaletteHeatIndex(now);
|
||||
byte brightness = getPaletteBrightness();
|
||||
|
@ -50,16 +65,15 @@ void Lighting::updateRGB(int now) {
|
|||
if (_weather->getCondition() == WeatherCondition::Thunder && millis() >= _nextLightningFlash) {
|
||||
int flashes = random8(2, 8);
|
||||
for (int i = 0; i < flashes; i++) {
|
||||
FastLED.showColor(CRGB::White);
|
||||
outputColour(CRGB::White);
|
||||
delay(random8(10, 20));
|
||||
FastLED.showColor(colour);
|
||||
outputColour(colour);
|
||||
delay(random8(40, 80));
|
||||
}
|
||||
_nextLightningFlash = millis() + (random8(1, 60) * 1000);
|
||||
}
|
||||
|
||||
fill_solid(_leds, _ledCount, colour);
|
||||
FastLED.show();
|
||||
outputColour(colour);
|
||||
}
|
||||
_lastHeatIndex = heatIndex;
|
||||
_lastBrightness = brightness;
|
||||
|
@ -69,7 +83,7 @@ void Lighting::updateWhite(){
|
|||
float brightness = (_heatIndex - 0.5) / 0.5;
|
||||
if (brightness<0)
|
||||
brightness = 0;
|
||||
analogWrite(_whitePin, 1024 * brightness);
|
||||
analogWrite(_whitePin, PWMRANGE * brightness);
|
||||
}
|
||||
|
||||
void Lighting::update(int now) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue