|
本帖最后由 Guofuqiang01 于 2021-3-25 09:27 编辑
疑问:是否购买专业版本之后使用专业key就可以用这个程序?
在楼主的程序里面添加以下程序实现双色温控制。
//第一段
//定义灯接口
#define ColdLED D2
#define WarmLED D3
//定义冷暖色灯输出值
int CVal,WVal;
//第二段在void changeLight(){}加入
void changeLight(){
//根据brightness,colortemp两参数调整灯
if(switchState=="on"){
CVal =map(brightness*colortemp/255,0,(colortemp+1),0,1023); //亮度参数从0到设置色温映射到1023(ESP8266的模拟量输出默认Range为1023)
WVal =map(brightness*(255-colortemp)/255,0,(256-colortemp),0,1023); //映射的原始范围选用0~256,为了避免colortemp值为0和255的时候出错
analogWrite(ColdLED,CVal);
analogWrite(WarmLED,WVal);
}
else if(switchState=="off"){
analogWrite(ColdLED,LOW);
analogWrite(WarmLED,LOW);
}
}
//第三段在void switch_callback(const String & state){}中加入
void switch_callback(const String & state)
{
if (state == BLINKER_CMD_ON) {
digitalWrite(LED_BUILTIN, HIGH);
analogWrite(ColdLED,CVal);
analogWrite(WarmLED,WVal);
switchState = "on";
}
else {
digitalWrite(LED_BUILTIN, LOW);
analogWrite(ColdLED,LOW);
analogWrite(WarmLED,LOW);
switchState = "off";
}
BUILTIN_SWITCH.print(switchState);
}
|
|