完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
我想用 nodemcu 0.9(esp-12 模块)做一个家庭自动化项目。但是当我编译出现错误时,(我从一个名为“saurabh lanje”的 youtube 频道发现了这个想法。)任何人都可以帮助我。请请请
代码:全选 #define BLYNK_PRINT Serial #include #include #include Blynktimer timer; #define DEBUG_SW 1 // Pins for Fan Regulator Knob #define s1 12 //D6 #define s2 13 //D7 #define s3 15 //D8 #define s4 16 //D0 // Pins for Switches #define S5 9 //SD2 #define S6 10 //SD3 // Pins for Relay (Appliances Control) #define R5 5 //D1 #define R6 4 //D2 // Pins for Relay (Fan Speed Control) #define Speed1 0 //D3 #define Speed2 2 //D4 #define Speed4 14 //D5 // By default the mode is with_internet int MODE = 0; // You should get Auth Token in the Blynk App or in Gmail. // Go to the Project Settings (nut icon). char auth[] = "AUTH TOKEN"; // Your WiFi credentials. // Set password to "" for open networks. char ssid[] = "WIFI NAME"; char pass[] = "PASS"; bool speed1_flag = 1; bool speed2_flag = 1; bool speed3_flag = 1; bool speed4_flag = 1; bool speed0_flag = 1; int switch_ON_Flag1_previous_I = 0; int switch_ON_Flag2_previous_I = 0; BLYNK_WRITE(V0) { int fan_speed = param.asInt(); // assigning incoming value from pin V1 to a variable if (fan_speed == 0) { speed0(); } if (fan_speed == 1) { speed1(); } if (fan_speed == 2) { speed2(); } if (fan_speed == 3) { speed3(); } if (fan_speed == 4) { speed4(); } } BLYNK_WRITE(V1) { int pinValue = param.asInt(); // assigning incoming value from pin V1 to a variable digitalWrite(R5, pinValue); // process received value } BLYNK_WRITE(V2) { int pinValue = param.asInt(); // assigning incoming value from pin V2 to a variable digitalWrite(R6, pinValue); // process received value } void setup() { // put your setup code here, to run once: pinMode(s1, INPUT); pinMode(s2, INPUT); pinMode(s3, INPUT); pinMode(s4, INPUT); pinMode(S5, INPUT); pinMode(S6, INPUT); pinMode(R5, OUTPUT); pinMode(R6, OUTPUT); pinMode(Speed1, OUTPUT); pinMode(Speed2, OUTPUT); pinMode(Speed4, OUTPUT); Serial.begin(9600); WiFi.begin(ssid, pass); timer.setInterval(3000L, checkBlynk); // check if connected to Blynk server every 3 seconds Blynk.config(auth);//, ssid, pass); } void loop() { if (WiFi.status() != WL_CONNECTED) { if (DEBUG_SW) Serial.println("Not Connected"); } else { if (DEBUG_SW) Serial.println(" Connected"); Blynk.run(); } timer.run(); // Initiates SimpleTimer if (MODE == 0) with_internet(); else without_internet(); // put your main code here, to run repeatedly: } void with_internet() { // FOR FAN if (digitalRead(s1) == HIGH && digitalRead(s2) == LOW && digitalRead(s3) == LOW && digitalRead(s4) == LOW && speed1_flag == 1) { speed1(); Blynk.virtualWrite(V0, 1); speed1_flag = 0; speed2_flag = 1; speed3_flag = 1; speed4_flag = 1; speed0_flag = 1; } if (digitalRead(s1) == LOW && digitalRead(s2) == HIGH && digitalRead(s3) == LOW && digitalRead(s4) == LOW && speed2_flag == 1) { speed2(); Blynk.virtualWrite(V0, 2); speed1_flag = 1; speed2_flag = 0; speed3_flag = 1; speed4_flag = 1; speed0_flag = 1; } if (digitalRead(s1) == LOW && digitalRead(s2) == LOW && digitalRead(s3) == HIGH && digitalRead(s4) == LOW && speed3_flag == 1) { speed3(); Blynk.virtualWrite(V0, 3); speed1_flag = 1; speed2_flag = 1; speed3_flag = 0; speed4_flag = 1; speed0_flag = 1; } if (digitalRead(s1) == LOW && digitalRead(s2) == LOW && digitalRead(s3) == LOW && digitalRead(s4) == HIGH && speed4_flag == 1) { speed4(); Blynk.virtualWrite(V0, 4); speed1_flag = 1; speed2_flag = 1; speed3_flag = 1; speed4_flag = 0; speed0_flag = 1; } if (digitalRead(s1) == LOW && digitalRead(s2) == LOW && digitalRead(s3) == LOW && digitalRead(s4) == LOW && speed0_flag == 1) { speed0(); Blynk.virtualWrite(V0, 0); speed1_flag = 1; speed2_flag = 1; speed3_flag = 1; speed4_flag = 1; speed0_flag = 0; } // FOR SWITCH if (digitalRead(S5) == LOW) { if (switch_ON_Flag1_previous_I == 0 ) { digitalWrite(R5, HIGH); if (DEBUG_SW) Serial.println("Relay1- ON"); Blynk.virtualWrite(V1, 1); switch_ON_Flag1_previous_I = 1; } if (DEBUG_SW) Serial.println("Switch1 -ON"); } if (digitalRead(S5) == HIGH ) { if (switch_ON_Flag1_previous_I == 1) { digitalWrite(R5, LOW); if (DEBUG_SW) Serial.println("Relay1 OFF"); Blynk.virtualWrite(V1, 0); switch_ON_Flag1_previous_I = 0; } if (DEBUG_SW)Serial.println("Switch1 OFF"); } if (digitalRead(S6) == LOW) { if (switch_ON_Flag2_previous_I == 0 ) { digitalWrite(R6, HIGH); if (DEBUG_SW) Serial.println("Relay2- ON"); Blynk.virtualWrite(V2, 1); switch_ON_Flag2_previous_I = 1; } if (DEBUG_SW) Serial.println("Switch2 -ON"); } if (digitalRead(S6) == HIGH ) { if (switch_ON_Flag2_previous_I == 1) { digitalWrite(R6, LOW); if (DEBUG_SW) Serial.println("Relay2 OFF"); Blynk.virtualWrite(V2, 0); switch_ON_Flag2_previous_I = 0; } if (DEBUG_SW)Serial.println("Switch2 OFF"); //delay(200); } } void without_internet() { // FOR FAN if (digitalRead(s1) == HIGH && digitalRead(s2) == LOW && digitalRead(s3) == LOW && digitalRead(s4) == LOW && speed1_flag == 1) { speed1(); speed1_flag = 0; speed2_flag = 1; speed3_flag = 1; speed4_flag = 1; speed0_flag = 1; } if (digitalRead(s1) == LOW && digitalRead(s2) == HIGH && digitalRead(s3) == LOW && digitalRead(s4) == LOW && speed2_flag == 1) { speed2(); speed1_flag = 1; speed2_flag = 0; speed3_flag = 1; speed4_flag = 1; speed0_flag = 1; } if (digitalRead(s1) == LOW && digitalRead(s2) == LOW && digitalRead(s3) == HIGH && digitalRead(s4) == LOW && speed3_flag == 1) { speed3(); speed1_flag = 1; speed2_flag = 1; speed3_flag = 0; speed4_flag = 1; speed0_flag = 1; } if (digitalRead(s1) == LOW && digitalRead(s2) == LOW && digitalRead(s3) == LOW && digitalRead(s4) == HIGH && speed4_flag == 1) { speed4(); speed1_flag = 1; speed2_flag = 1; speed3_flag = 1; speed4_flag = 0; speed0_flag = 1; } if (digitalRead(s1) == LOW && digitalRead(s2) == LOW && digitalRead(s3) == LOW && digitalRead(s4) == LOW && speed0_flag == 1) { speed0(); speed1_flag = 1; speed2_flag = 1; speed3_flag = 1; speed4_flag = 1; speed0_flag = 0; } } // FOR SWITCH digitalWrite(R5, !digitalRead(S5)); digitalWrite(R6, !digitalRead(S6)); } // Fan Speed Control void speed0() { //All Relays Off - Fan at speed 0 if (DEBUG_SW)Serial.println("SPEED 0"); digitalWrite(Speed1, HIGH); digitalWrite(Speed2, HIGH); digitalWrite(Speed4, HIGH); } void speed1() { //Speed1 Relay On - Fan at speed 1 if (DEBUG_SW)Serial.println("SPEED 1"); digitalWrite(Speed1, HIGH); digitalWrite(Speed2, HIGH); digitalWrite(Speed4, HIGH); delay(500); digitalWrite(Speed1, LOW); } void speed2() { //Speed2 Relay On - Fan at speed 2 if (DEBUG_SW)Serial.println("SPEED 2"); digitalWrite(Speed1, HIGH); digitalWrite(Speed2, HIGH); digitalWrite(Speed4, HIGH); delay(500); digitalWrite(Speed2, LOW); } void speed3() { //Speed1 & Speed2 Relays On - Fan at speed 3 if (DEBUG_SW)Serial.println("SPEED 3"); digitalWrite(Speed1, HIGH); digitalWrite(Speed2, HIGH); digitalWrite(Speed4, HIGH); delay(500); digitalWrite(Speed1, LOW); digitalWrite(Speed2, LOW); } void speed4() { //Speed4 Relay On - Fan at speed 4 if (DEBUG_SW)Serial.println("SPEED 4"); digitalWrite(Speed1, HIGH); digitalWrite(Speed2, HIGH); digitalWrite(Speed4, HIGH); Blynk.virtualWrite(V4, 0); delay(500); digitalWrite(Speed4, LOW); } //Check Blynk Connectivity every 3 seconds void checkBlynk() { bool isconnected = Blynk.connected(); if (isconnected == false) { MODE = 1; } if (isconnected == true) { MODE = 0; } } |
|
相关推荐
1个回答
|
|
一些常见方法:
1. 检查您使用的软件版本和库是否与您的硬件兼容,并根据需要进行更新或更换。 2. 检查您的代码是否有语法错误或拼写错误。您可以使用IDE自带的代码检查器来帮助识别错误。 3. 尝试使用其他编译器,例如Arduino IDE或PlatformIO等。 |
|
|
|
只有小组成员才能发言,加入小组>>
171个成员聚集在这个小组
加入小组382 浏览 1 评论
1217 浏览 1 评论
592浏览 6评论
486浏览 5评论
有没有办法在不使用混杂模式的情况下实现Wifi驱动程序接收缓冲区访问中断呢?
471浏览 5评论
469浏览 4评论
447浏览 4评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2025-1-2 03:29 , Processed in 0.922626 second(s), Total 81, Slave 64 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号