无线局域网课程作业1
编译环境:Mind+
硬件:掌控板
实验1光控灯
图形化
实现代码
/*!
* MindPlus
* mpython
*
*/
#include <MPython.h>
// 主程序开始
void setup() {
mPython.begin();
}
void loop() {
display.setCursorLine(1);
display.printLine((light.read()));
delay(5000);
if (((light.read())<=2500)) {
for (int index = 0; index < 10; index++) {
rgb.write(-1, 0x3366FF);
yield();
}
}
else {
rgb.write(-1, 0x000000);
}
}
效果图
实验2声控灯
图形化
实现代码
/*!
* MindPlus
* mpython
*
*/
#include <MPython.h>
// 主程序开始
void setup() {
mPython.begin();
}
void loop() {
display.setCursorLine(1);
display.printLine((sound.read()));
delay(1000);
if (((sound.read())>=500)) {
for (int index = 0; index < 10; index++) {
rgb.write(-1, 0x3366FF);
yield();
}
}
else {
rgb.write(-1, 0x000000);
}
}
效果图
实验3语音识别控制灯
图形化
效果图
实验4实现Easy IoT上mqtt消息的通讯
图形化
实现代码
/*!
* MindPlus
* mpython
*
*/
#include <MPython.h>
#include <DFRobot_Iot.h>
// 函数声明
void onButtonAPressed();
void obloqMqttEventT0(String& message);
// 静态常量
const String topics[5] = {"wRcH8COMR","VeCisCdMR","","",""};
const MsgHandleCb msgHandles[5] = {obloqMqttEventT0,NULL,NULL,NULL,NULL};
// 创建对象
DFRobot_Iot myIot;
// 主程序开始
void setup() {
mPython.begin();
myIot.setMqttCallback(msgHandles);
buttonA.setPressedCallback(onButtonAPressed);
myIot.wifiConnect("shenshian", "zrr123123");
display.setCursorLine(1);
display.printLine("WIFI正在连接");
while (!myIot.wifiStatus()) {yield();}
display.setCursorLine(1);
display.printLine("WIFI连接成功");
myIot.init("iot.dfrobot.com.cn","Rf4tCjCWg","","RB4tjCCWRz",topics,1883);
myIot.connect();
while (!myIot.connected()) {yield();}
display.setCursorLine(2);
display.printLine("MQTT连接成功");
}
void loop() {
}
// 事件回调函数
void onButtonAPressed() {
myIot.publish(topic_1, "标爷你好帅");
display.setCursorLine(3);
display.printLine("郑荣瑞发送成功");
}
void obloqMqttEventT0(String& message) {
display.setCursorLine(4);
display.printLine(message);
}
效果图