標(biāo)題:
小愛師兄控制家用燈泡 Arduino程序
[打印本頁]
作者:
wW123xz
時(shí)間:
2020-3-12 17:57
標(biāo)題:
小愛師兄控制家用燈泡 Arduino程序
無論是零器件采購,或者是程序有不懂或者不明白的地方都可以回帖找我
單片機(jī)源程序如下:
#define BLINKER_WIFI
#define BLINKER_MIOT_OUTLET //小愛師兄
#include <Blinker.h>
char auth[] = "daa5bb3f1a9f"; //設(shè)備key
char ssid[] = "JCG-572D74"; //路由器wifi ssid
char pswd[] = "tmtmtmtm"; //路由器wifi 密碼
BlinkerButton Button1("btn-abc"); //定義按鈕鍵名
bool oState = false;
int counter = 0;
void miotPowerState(const String & state)
{
BLINKER_LOG("need set power state: ", state);
if (state == BLINKER_CMD_ON) { //小愛師兄控制開命令 此處修改為點(diǎn)動(dòng)模式,適合按鈕操作,
digitalWrite(0, LOW);
BlinkerMIOT.powerState("on");
BlinkerMIOT.print();
oState = true;
}
else if (state == BLINKER_CMD_OFF) { //小愛師兄控制關(guān)命令 此處修改為點(diǎn)動(dòng)模式,適合按鈕操作,
digitalWrite(0, HIGH);
BlinkerMIOT.powerState("off");
BlinkerMIOT.print();
oState = false;
}
}
void miotQuery(int32_t queryCode) //小愛師兄控制
{
BLINKER_LOG("MIOT Query codes: ", queryCode);
switch (queryCode)
{
case BLINKER_CMD_QUERY_ALL_NUMBER :
BLINKER_LOG("MIOT Query All");
BlinkerMIOT.powerState(oState ? "on" : "off");
BlinkerMIOT.print();
break;
case BLINKER_CMD_QUERY_POWERSTATE_NUMBER :
BLINKER_LOG("MIOT Query Power State");
BlinkerMIOT.powerState(oState ? "on" : "off");
BlinkerMIOT.print();
break;
default :
BlinkerMIOT.powerState(oState ? "on" : "off");
BlinkerMIOT.print();
break;
}
}
void dataRead(const String & data) // 如果未綁定的組件被觸發(fā),則會(huì)執(zhí)行其中內(nèi)容
{
BLINKER_LOG("Blinker readString: ", data);
Blinker.vibrate();
uint32_t BlinkerTime = millis();
Blinker.print("millis", BlinkerTime);
}
void button1_callback(const String & state) //點(diǎn)燈app內(nèi)控制按鍵觸發(fā)
{
BLINKER_LOG("get button state: ", state);
digitalWrite(0,LOW);
delay(200);
digitalWrite(0, HIGH);
}
void setup()
{
Serial.begin(115200);
BLINKER_DEBUG.stream(Serial);
pinMode(0, OUTPUT); //定義io口為輸出
digitalWrite(0, HIGH); //定義io默認(rèn)為高電平
Blinker.begin(auth, ssid, pswd);
Blinker.attachData(dataRead);
BlinkerMIOT.attachPowerState(miotPowerState);
BlinkerMIOT.attachQuery(miotQuery);
Button1.attach(button1_callback);
}
void loop()
{
Blinker.run();
}
復(fù)制代碼
所有資料51hei提供下載:
小愛-燈泡.zip
(759.29 KB, 下載次數(shù): 10)
2020-3-12 17:55 上傳
點(diǎn)擊文件名下載附件
下載積分: 黑幣 -5
作者:
admin
時(shí)間:
2020-3-12 22:43
本帖需要重新編輯補(bǔ)全電路原理圖,源碼,詳細(xì)說明與圖片即可獲得100+黑幣(帖子下方有編輯按鈕)
作者:
3310mad2
時(shí)間:
2020-3-12 23:05
添加些圖片及說明吧,都不知道這個(gè)都有什么功能
歡迎光臨 (http://www.torrancerestoration.com/bbs/)
Powered by Discuz! X3.1