我打算将运动传感器与blynk应用程序运行合并,但是此错误使我停滞不前,我真的不知道出了什么问题。我做了本教程要求我做的事情,但仍然无法弄清代码出了什么错误:
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
char auth[] = "6Ou9LvxXsYMx162V3Rsij4fmcU-AgOQT";
char ssid[] = "MSI 1251";
char pass[] = "1=A864d0";
volatile boolean pirState = 0; // Initialize the variable with 0 value.
void setup()
{
Serial.begin(9600);
pinMode(D1,OUTPUT);
pinMode(D2,OUTPUT);
pinMode(D3,OUTPUT);
pinMode(D4,OUTPUT);
digitalWrite(D1,HIGH);
digitalWrite(D2,HIGH);
digitalWrite(D3,HIGH);
digitalWrite(D4,HIGH);
Blynk.begin(auth, ssid, pass);
pinMode(7, OUTPUT); // Initialize digital pin 13 as an output.
pinMode(2, INPUT); // Initialize digital pin 2 as an input.
attachInterrupt(digitalPinToInterrupt(2),pirResponse,CHANGE ); // This command is used to set PIN 2 in interrupt mode on arduino. pirResponse is the ISR (code that will be executed when interrupt is raised).
}
void loop()
{
Blynk.run();
}
voidpirResponse() // Function to moniotr the detection motion.
{
if (pirState==1) // Monitors the status of variable
{
pirState=0; // Makes pirstate to 0 in order to proceed for further process.
digitalWrite(7,LOW); // If motion not detected then turns OFF the LED which is connected to digital pin 7.
}
else
{
pirState=1; // Makes pirState to 0 in order to proceed for further process.
digitalWrite(7,HIGH); // If motion detected then turns ON the LED which is connected to digital pin 7.
}
}