main
#include <ESP8266WiFi.h>
#include "config.h"
#define BLINKER_PRINT Serial
#define BLINKER_WIFI
#include <Blinker.h>
char auth[] = "9bd88da46b95";//APP密钥//
int R_VAL=202;
int G_VAL=215;
int B_VAL=0;
#define R_PIN 4 //定义LED2灯引脚
#define G_PIN 5 //定义LED1灯引脚
#define B_PIN 14 //定义LED5灯引脚
int buttonPin = 0; // 按键的管脚定义
// 新建组件对象
BlinkerButton Button1("btn-abc");
BlinkerNumber Number1("num-abc");
BlinkerRGB RGB1("col-9bf");
int counter = 0;
// 按下按键即会执行该函数
void button1_callback(const String & state) {
BLINKER_LOG("get button state: ", state);
Button1.print("off");
if(state=="on")
{
R_VAL= 255;//越大越亮,三种灯的亮暗程度不同显示不同的颜色,全亮//
G_VAL= 255;
B_VAL= 255;
}
else if(state=="off")
{
R_VAL= 0;//全灭//
G_VAL= 0;
B_VAL= 0;
}
analogWrite(R_PIN, 1023-R_VAL*4);//将255放大1023,再将1023变成0,1022变成1······//
analogWrite(G_PIN, 1023-G_VAL*4);
analogWrite(B_PIN, 1023-B_VAL*4);
}
// 如果未绑定的组件被触发,则会执行其中内容
void dataRead(const String & data)
{
BLINKER_LOG("Blinker readString: ", data);
counter++;
Number1.print(counter);
}
void rgb1_callback(uint8_t r_value, uint8_t g_value,uint8_t b_value, uint8_t bright_value)
{
digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
BLINKER_LOG("R value: ", r_value);
BLINKER_LOG("G value: ", g_value);
BLINKER_LOG("B value: ", b_value);
BLINKER_LOG("Rrightness value: ", bright_value);
R_VAL= r_value;
G_VAL= g_value;
B_VAL= b_value;
analogWrite(R_PIN, 1023-R_VAL*4);//将255放大1023,再将1023变成0,1022变成1······//
analogWrite(G_PIN, 1023-G_VAL*4);
analogWrite(B_PIN, 1023-B_VAL*4);
}
void setup() {
Serial.begin(115200);
Serial.println("star");//串口输出打印//
String name_1=reader("name");
String pwd_1=reader("pwd");
char name_2[name_1.length()+1];
char pwd_2[pwd_1.length()+1];
for(int i=0;i<name_1.length();i++)
name_2[i]=name_1[i];
name_2[name_1.length()]='\0';
for(int i=0;i<pwd_1.length();i++)
pwd_2[i]=pwd_1[i];
pwd_2[pwd_1.length()]='\0';
Serial.println(name_1);//串口输出打印//
Serial.println(pwd_1);//串口输出打印//
Serial.println(name_2);//串口输出打印//
Serial.println(pwd_2);//串口输出打印//
#if defined(BLINKER_PRINT)
BLINKER_DEBUG.stream(BLINKER_PRINT);
#endif
// 初始化有LED的IO
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, HIGH);
// 初始化blinker
Blinker.begin(auth, name_2, pwd_2);
Blinker.attachData(dataRead);
RGB1.attach(rgb1_callback);
Button1.attach(button1_callback);
pinMode(R_PIN,OUTPUT); //设定LED2引脚为输出
pinMode(G_PIN,OUTPUT); //设定LED3引脚为输出
pinMode(B_PIN,OUTPUT); //设定LED4引脚为输出
pinMode(buttonPin, INPUT_PULLUP); //设置按键管脚上拉输入模式
}
char flag=0;
void loop() {
if(flag==0)
{
Blinker.run();
if (digitalRead(buttonPin) == LOW) { // 若按键被按下
delay(100);
if (digitalRead(buttonPin) == LOW) { // 延时消抖
Serial.println("=============wifi config===============");//串口输出打印//
flag=1;
}
}
}
else if(flag==1)
{
myWebConfig_init();
flag=2;
}else if(flag==2)
{
myWebConfig_run();
}
//
}