Lighting improvements

This commit is contained in:
Robert Marshall 2018-09-16 15:40:44 +01:00
parent b134bc0334
commit 99019edd1d
2 changed files with 15 additions and 35 deletions

View file

@ -1,5 +1,5 @@
{
"port": "/dev/ttyUSB1",
"port": "/dev/ttyUSB0",
"board": "esp8266:esp8266:d1_mini",
"configuration": "CpuFrequency=80,FlashSize=4M1M,LwIPVariant=v2mss536,Debug=Disabled,DebugLevel=None____,UploadSpeed=921600",
"sketch": "monitor.ino"

View file

@ -33,7 +33,7 @@ PubSubClient client = PubSubClient(MQTT_SERVER, 1883, mqttCallback, wifiClient);
CRGB leds[LED_COUNT];
bool lightsOn = true;
static const uint8_t sunriseLength = 1;
static const uint8_t sunriseLength = 30;
static const uint8_t heatIndexMax = 240;
static const float lightChangeInterval = ((float)(sunriseLength * 60) / heatIndexMax) * 1000;
static uint8_t heatIndex = 0;
@ -83,7 +83,7 @@ void setup() {
WiFi.begin(SSID, PASSWORD);
reconnect();
FastLED.addLeds<WS2811, LIGHT_PIN, GRB>(leds, LED_COUNT).setCorrection(TypicalSMD5050).setTemperature(Tungsten40W);
FastLED.addLeds<WS2811, LIGHT_PIN, GRB>(leds, LED_COUNT).setCorrection(TypicalSMD5050);//.setTemperature(Tungsten40W);
Serial.print("Light interval: ");
Serial.println(lightChangeInterval);
@ -130,44 +130,24 @@ void publishTemperature() {
client.publish(TEMPERATURE_TOPIC, temperatureString.c_str(), true);
}
void sunrise() {
CRGB color = ColorFromPalette(HeatColors_p, heatIndex);
fill_solid(leds, LED_COUNT, color);
EVERY_N_MILLISECONDS(lightChangeInterval) {
if (heatIndex < heatIndexMax)
heatIndex++;
}
}
void sunset() {
CRGB color = ColorFromPalette(HeatColors_p, heatIndex);
fill_solid(leds, LED_COUNT, color);
EVERY_N_MILLISECONDS(lightChangeInterval) {
if (heatIndex > 0)
heatIndex--;
}
}
void doLighting() {
CRGB color = ColorFromPalette(HeatColors_p, heatIndex);
fill_solid(leds, LED_COUNT, color);
EVERY_N_MILLISECONDS(lightChangeInterval) {
if (lightsOn && heatIndex < heatIndexMax)
heatIndex++;
else if (heatIndex > 0)
heatIndex--;
CRGB color = ColorFromPalette(HeatColors_p, heatIndex);
fill_solid(leds, LED_COUNT, color);
if (lightsOn){
if(heatIndex < heatIndexMax)
heatIndex++;
} else {
if (heatIndex > 0)
heatIndex--;
}
Serial.print("Heat index: ");
Serial.println(heatIndex);
}
FastLED.show();
FastLED.show();
}
}
void publishReadings(){