esp8266接入点灯科技
/*
@author :
*/
#define BLINKER_WIFI//以WiFi方式接入blinker
#define BLINKER_MIOT_LIGHT
#include <Blinker.h>
#include <Wire.h>
#include "OLED.h"
OLED display(4, 5);
//定义LED灯引脚
#define LED_R 16
#define LED_G 5
#define LED_B 4
char auth[] = "3c613a6b2336";//定义Device Secret Key,从blinker APP获取
char ssid[] = "TP-LINK_1779";//WiFi name
char pswd[] = "123456a?";//WiFi password
// 新建组件对象
BlinkerButton button_R("btn-86a");//红灯按钮
BlinkerButton button_G("btn-r3m");//绿灯按钮
BlinkerButton button_B("btn-7c6");//蓝灯按钮
void R_callback(const String &state)//红灯回调函数
{
// digitalWrite(LED_R,!digitalRead(LED_R));
BLINKER_LOG("R_val:",state);
display.clear();
display.print("red",2,2);
Serial.println("rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrred");
}
void G_callback(const String &state)//绿灯回调函数
{
// digitalWrite(LED_G,!digitalRead(LED_G));
BLINKER_LOG("G_val:",state);
display.clear();
display.print("green",2,2);
Serial.println("ggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggreen");
}
void B_callback(const String &state)//蓝灯回调函数
{
// digitalWrite(LED_B,!digitalRead(LED_B));
BLINKER_LOG("B_val:",state);
display.clear();
display.print("blue",2,2);
Serial.println("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbblue");
}
void setup()
{
display.begin();
display.print("startup",0,0);
// 初始化串口
Serial.begin(115200);
BLINKER_DEBUG.stream(Serial);
BLINKER_DEBUG.debugAll();
display.print("com is ok",2,0);
// // 初始化LED灯
// pinMode(LED_R,OUTPUT);
// pinMode(LED_G,OUTPUT);
// pinMode(LED_B,OUTPUT);
// digitalWrite(LED_R,HIGH);
// digitalWrite(LED_G,HIGH);
// digitalWrite(LED_B,HIGH);
display.print("led is ok",4,0);
// 初始化blinker
Blinker.begin(auth, ssid, pswd);
display.print("blk is ok",2,0);
//回调函数注册
button_R.attach(R_callback);
button_G.attach(G_callback);
button_B.attach(B_callback);
display.print("fun is ok",6,0);
}
void loop() {
//display.begin();
//display.print("...",2,0);
//Blinker运行
Blinker.run();
}