基于Blinker程序编写的小爱同学控制双色温吸顶灯程序
硬件:ESP8266、MOS管、双色温LED灯
程序如下:
#define BLINKER_PRO_ESP
#define BLINKER_WITHOUT_SSL
#define BLINKER_BUTTON
#define BLINKER_BUTTON_LONGPRESS_POWERDOWN
#if defined(ESP32)
#define BLINKER_BUTTON_PIN 4
#else
#define BLINKER_BUTTON_PIN D7
#endif
#define BLINKER_OTA_VERSION_CODE "0.1.1"
#define BLINKER_MIOT_LIGHT
#include <Blinker.h>
char type[] = "EjtbFjnSLpL6"; //不需要修改
char auth[] = "AU1ldFdhHy7z"; //不需要修改
//定义灯接口
#define ColdLED D2
#define WarmLED D3
//定义冷暖色温输出值
int CVal,WVal;
// 设备状态
String switchState = "on";
int modeState = 0;
int brightvalue = 0; //brightness定义和小爱回调及blinker库有冲突,故采用brightvalue
int colortemp = 0;
bool oState = false;
//定义小爱电源类回调函数
void miotPowerState(const String & state)
{
BLINKER_LOG("need set power state: ", state);
if (state == BLINKER_CMD_ON)
{
digitalWrite(LED_BUILTIN, HIGH);
analogWrite(ColdLED,CVal);
analogWrite(WarmLED,WVal);
BlinkerMIOT.powerState("on");
BlinkerMIOT.print();
switchState = "on"; //给APP反馈按钮状态
oState = true; //给小爱同学反馈按钮状态
}
else if (state == BLINKER_CMD_OFF)
{
digitalWrite(LED_BUILTIN, LOW);
analogWrite(ColdLED,LOW);
analogWrite(WarmLED,LOW);
BlinkerMIOT.powerState("off");
Bli