339| 0
|
[项目分享] 代码分享-------控制红绿灯 |
/*! * MindPlus * uno * */ #include "DFRobot_DF2301Q.h" #include <DFRobot_Ultrasonic.h> #include <DFRobot_WiFi_IoT_Module.h> #include <DFRobot_LiquidCrystal_I2C.h> // 动态变量 volatile float mind_n_CheLiuLiang, mind_n_LvDengShiChang, mind_n_HongDengShiChang; // 函数声明 void obloqMqttEventT0(const char *obloq_message); // 静态常量 const String topics[5] = {"g46jRSkNR","","","",""}; const MqttHandle msgHandles[5] = {obloqMqttEventT0,NULL,NULL,NULL,NULL}; // 创建对象 DFRobot_WiFi_IoT_Module_UART olq; DFRobot_LiquidCrystal_I2C lcd1602; DFRobot_DF2301Q_I2C asrDF2301Q; DFRobot_Ultrasonic ultraA0; // 主程序开始 void setup() { olq.registerMqttHandle(msgHandles); ultraA0.begin(A0); olq.startConnect(0, 1, "HUAWEI-040RO6", "HCJ19841210", "9HslgSkHR", "rNy_RSkHRz", topics, "iot.dfrobot.com.cn", 1883); lcd1602.begin(0x20); lcd1602.clear(); mind_n_CheLiuLiang = 0; mind_n_LvDengShiChang = 50; mind_n_HongDengShiChang = 35; asrDF2301Q.setWakeTime(20); while (!(asrDF2301Q.begin())) {delay(3000);} asrDF2301Q.setMuteMode(0); asrDF2301Q.playByCMDID(23); } void loop() { if ((ultraA0.getDistanceCm()<=10)) { delay(500); mind_n_CheLiuLiang += 1; } digitalWrite(4, HIGH); delay(mind_n_LvDengShiChang * 1000); digitalWrite(4, LOW); digitalWrite(5, HIGH); delay(mind_n_HongDengShiChang * 1000); digitalWrite(5, LOW); int asrDF2301Q_CMDID = asrDF2301Q.getCMDID(); if ((not asrDF2301Q_CMDID==0)) { if (((asrDF2301Q_CMDID)==5)) { mind_n_LvDengShiChang = 75; } if (((asrDF2301Q_CMDID)==6)) { mind_n_LvDengShiChang = 50; } if (((asrDF2301Q_CMDID)==7)) { mind_n_LvDengShiChang = 20; } if (((asrDF2301Q_CMDID)==8)) { mind_n_HongDengShiChang = 55; } if (((asrDF2301Q_CMDID)==9)) { mind_n_HongDengShiChang = 35; } if (((asrDF2301Q_CMDID)==10)) { mind_n_HongDengShiChang = 20; } if (((asrDF2301Q_CMDID)==11)) { lcd1602.printLine(uint32_t(1), mind_n_CheLiuLiang); delay(1000); lcd1602.clear(); } } } // 事件回调函数 void obloqMqttEventT0(const char *obloq_message) { while (1) { delay(60000); olq.publish(olq.topic_0, mind_n_CheLiuLiang); mind_n_CheLiuLiang = 0; } } |
© 2013-2024 Comsenz Inc. Powered by Discuz! X3.4 Licensed