|
前辈们好,刚刚开始学习ARDUINO,还不能灵活运用,希望能得到指点
我要实现的功能是:MQ2,火焰和人体红外三个传感器进行报警然后通知手机
我看了BLINKER远程报警实例代码,分别用那个代码连接三个传感器都能独立工作,现在我想把他们合起来,然后我自己修改的代码是这样的,运行起来就有错误,报错异常,请前辈们指点一下。
#define BLINKER_PRINT Serial
#define BLINKER_WIFI
#include <Blinker.h>
char auth[] = "5f5b05a927c9";
char ssid[] = "ChinaNet-cAvK";
char pswd[] = "vckevzmt";
#define IR_DETEC_PIN D1
#define MQ_DETEC_PIN D2
#define HY_DETEC_PIN D3
uint32_t detect_os_time = millis();
bool isWarn = false;
void sensor_init()
{
pinMode(IR_DETEC_PIN, INPUT_PULLUP);
pinMode(MQ_DETEC_PIN, INPUT_PULLUP);
pinMode(HY_DETEC_PIN, INPUT_PULLUP);
}
void sensor_IR()
{
if (!digitalRead(IR_DETEC_PIN)) {
if (!isWarn) {
Blinker.notify("进r人了");
isWarn = true;
detect_os_time = millis();
}
else if (millis() - detect_os_time >= 10000) {
isWarn = false;
}
}
else {
isWarn = false;
}
}
void sensor_MQ()
{
if (!digitalRead(MQ_DETEC_PIN)) {
if (!isWarn) {
Blinker.notify("漏气了");
isWarn = true;
detect_os_time = millis();
}
else if (millis() - detect_os_time >= 10000) {
isWarn = false;
}
}
else {
isWarn = false;
}
}
void sensor_HY()
{
if (!digitalRead(HY_DETEC_PIN)) {
if (!isWarn) {
Blinker.notify("着火了");
isWarn = true;
detect_os_time = millis();
}
else if (millis() - detect_os_time >= 10000) {
isWarn = false;
}
}
else {
isWarn = false;
}
}
void setup()
{
Serial.begin(115200);
sensor_init();
Blinker.begin(auth, ssid, pswd);
}
void loop()
{
Blinker.run();
sensor_IR();
sensor_MQ();
sensor_HY();
}
|
|