diff --git a/examples/lightWithBrightness.cpp b/examples/lightWithBrightness.cpp index 96df56b..4333c83 100644 --- a/examples/lightWithBrightness.cpp +++ b/examples/lightWithBrightness.cpp @@ -89,6 +89,10 @@ void setup() { brightness=directive["payload"]["brightness"]; Serial.printf("setting brightness to: %d\n", brightness); outputState = PowerController::ON; + } else if(directive["header"]["name"]=="AdjustBrightness"){ // "dim" / "brighten" (by N percent) + brightness=constrain(brightness + (int)directive["payload"]["brightnessDelta"], 0, 100); + Serial.printf("adjusting brightness to: %d\n", brightness); + outputState = PowerController::ON; } }else{ return; diff --git a/examples/lightWithColorTemp.cpp b/examples/lightWithColorTemp.cpp index 7635915..b14ef1c 100644 --- a/examples/lightWithColorTemp.cpp +++ b/examples/lightWithColorTemp.cpp @@ -28,7 +28,7 @@ AlexaDevice* device1; // Initial state for the light (PowerController) PowerController outputState = PowerController::OFF; int brightness=100; -int colorTemp=0; +int colorTemp=2700; // Kelvin; Alexa accepts 1000-10000, so never report 0 void setup() { // Initialize the LED as output pinMode(LED_BUILTIN, OUTPUT); @@ -94,12 +94,20 @@ void setup() { brightness=directive["payload"]["brightness"]; Serial.printf("setting brightness to: %d\n", brightness); outputState = PowerController::ON; + } else if(directive["header"]["name"]=="AdjustBrightness"){ // "dim" / "brighten" (by N percent) + brightness=constrain(brightness + (int)directive["payload"]["brightnessDelta"], 0, 100); + Serial.printf("adjusting brightness to: %d\n", brightness); + outputState = PowerController::ON; } }else if (type == AlexaInterfaceType::COLOR_TEMPERATURE_CONTROLLER) { if(directive["header"]["name"]=="SetColorTemperature"){ colorTemp=directive["payload"]["colorTemperatureInKelvin"]; Serial.printf("setting color temperature to: %d\n", colorTemp); outputState = PowerController::ON; + } else if(directive["header"]["name"]=="IncreaseColorTemperature" || directive["header"]["name"]=="DecreaseColorTemperature"){ // "cooler" / "warmer" + colorTemp=constrain(colorTemp + (directive["header"]["name"]=="IncreaseColorTemperature" ? 500 : -500), 1000, 10000); + Serial.printf("adjusting color temperature to: %d\n", colorTemp); + outputState = PowerController::ON; } }else{ return;