光敏电阻数值低灯开,手机按键控制灯开,怎么让两者互不干扰
#define BLINKER_WIFI
#include <Blinker.h>
char auth[] = "xxxxxx";
char ssid[] = "xxxxx";
char pswd[] = "xxxxxx";
BlinkerButton Button1("btn-abc");//按键灯
BlinkerNumber LIGHT("light");
#define Aout A0
uint32_t read_time = 0;
float light_read;
float temp; //临时变量,存储A0读取的数据
void dataRead(const String & data)
{
BLINKER_LOG("Blinker readString: ", data);
Blinker.vibrate();
uint32_t BlinkerTime = millis();
Blinker.print("millis", BlinkerTime);
}
void heartbeat()
{
LIGHT.print(light_read);
}
// 按下按键即会执行该函数
void button1_callback(const String & state) {
BLINKER_LOG("get button state: ", state);
digitalWrite(16, !digitalRead(16));
Blinker.vibrate();
}
void setup()
{
Serial.begin(115200);
BLINKER_DEBUG.stream(Serial);
pinMode(Aout, INPUT);//定义A0为INPUT模式
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, LOW);
// 初始化按键控制的LED的IO
pinMode(16, OUTPUT);
digitalWrite(16, LOW);
Blinker.begin(auth, ssid, pswd);
Blinker.attachData(dataRead);
Blinker.attachHeartbeat(heartbeat);
Button1.attach(button1_callback);
}
void loop()
{
Blinker.run();
int l=analogRead(A0); //光敏的AO口
if (read_time == 0 || (millis() - read_time) >= 2000)
{
read_time = millis();
//灯
if(l<50){
digitalWrite(16,HIGH);
}else{
digitalWrite(16,LOW);
}
}
light_read = l;
BLINKER_LOG("L: ",l);
Blinker.delay(2000);
}
|