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();
|
||||
}
|
10
Lighting.h
10
Lighting.h
|
@ -12,7 +12,7 @@ DEFINE_GRADIENT_PALETTE(_sunrise_p) {
|
|||
};
|
||||
|
||||
class Lighting {
|
||||
int _ledCount;
|
||||
int _ledCount, _whitePin;
|
||||
NaturalLight* _naturalLight;
|
||||
Weather* _weather;
|
||||
float _cloudCoverLimit;
|
||||
|
@ -25,13 +25,19 @@ class Lighting {
|
|||
float _currentHeatIndex();
|
||||
float getIndexMultiplier(int now, int startTime, int endTime, bool swap);
|
||||
float getHeatIndex(int time);
|
||||
float getPaletteHeatIndex(int time);
|
||||
float getBrightness();
|
||||
float getPaletteBrightness();
|
||||
void updateRGB(int now);
|
||||
void updateWhite();
|
||||
|
||||
public:
|
||||
Lighting(int ledCount, NaturalLight* _naturalLight, Weather* _weather, float cloudCoverLimit);
|
||||
|
||||
template<uint8_t DATA_PIN> void setup() {
|
||||
template<uint8_t DATA_PIN, int WHITE_PIN> void setup() {
|
||||
FastLED.addLeds<WS2811, DATA_PIN, GRB>(_leds, _ledCount).setCorrection(TypicalSMD5050).setTemperature(Tungsten40W);
|
||||
_whitePin = WHITE_PIN;
|
||||
pinMode(_whitePin, OUTPUT);
|
||||
}
|
||||
void update(int time);
|
||||
float getCurrentHeatIndex() { return _heatIndex; }
|
||||
|
|
|
@ -16,8 +16,9 @@
|
|||
#define TEMPERATURE_TOPIC "/home/sensors/fishtank/temperature"
|
||||
#define TEMPERATURE_PIN D5
|
||||
|
||||
#define LED_PIN D2
|
||||
#define LED_COUNT 36
|
||||
#define RGB_PIN D3
|
||||
#define WHITE_PIN D2
|
||||
#define LED_COUNT 39
|
||||
#define LATITUDE "20.548103"
|
||||
#define LONGITUDE "96.916835"
|
||||
#define TIMEZONE_OFFSET 27000 // 7.5 hours in seconds
|
||||
|
@ -45,7 +46,7 @@ void setup() {
|
|||
|
||||
_naturalLight.update();
|
||||
_weather.update();
|
||||
_lighting.setup<LED_PIN>();
|
||||
_lighting.setup<RGB_PIN, WHITE_PIN>();
|
||||
}
|
||||
|
||||
void publishFloat(char* topic, float value){
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue