[掌控板2.0]Mind+图形化编程实验1

本文介绍了使用Mind+图形化编程软件对掌控板进行编程的四个实验:光控灯、声控灯、语音识别控制灯及EasyIoT平台上的mqtt消息通讯。实验详细展示了从硬件连接到软件编程的具体步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

[掌控板2.0]Mind+图形化编程实验1

实验软硬件环境

  1. 硬件:掌控版、数据线
  2. 软件:Mind+ (V1.6.5 RC1.0)

实验目的及要求

【实验一】光控灯
【实验二】声控灯
【实验三】语音识别控制灯
【实验四】实现Easy IoT上mqtt消息的通讯。甲按A键(或触摸P)发送消息至topic1,同时监听topic0。乙监听topic1,接收到甲的消息后按A(或触摸P)回复消息给topic0甲显示。

实验原理与内容

  1. 实现天黑自动亮灯,天亮灭灯。
  2. 实现声音强度到一定程度自动亮度,否则灭灯。
  3. 实现语音控制灯的开关。
  4. 实现mind+下Easy IoT上mqtt消息的通讯。

实验过程

连接掌控版
通过以下3步完成掌控板在Mind+中的连接设置。
将掌控板通过数据线连接到电脑;
打开Mind+软件,选择“上传模式
单击“扩展” ,弹出如下窗口,选择“主控板”后,单击“掌控板”。
在这里插入图片描述
【实验一】光控灯
核心代码截图:

C语言代码:

#include <MPython.h>


// 主程序开始
void setup() {
	mPython.begin();
}
void loop() {
	display.setCursorLine(1);
	display.printLine((String("当前环境光强度:") + String((light.read()))));
	delay(1000);
	if (((light.read())<50)) {
		rgb.write(-1, 0xFFFFFF);
		display.setCursorLine(2);
		display.printLine("灯已打开");
	}
	else {
		rgb.write(-1, 0x000000);
		display.setCursorLine(2);
		display.printLine("灯已关闭");
	}
}

实验效果图:
在这里插入图片描述
在这里插入图片描述
【实验二】声控灯
核心代码截图:
在这里插入图片描述
C语言代码:

#include <MPython.h>
// 主程序开始
void setup() {
	mPython.begin();
}
void loop() {
	display.setCursorLine(1);
	display.printLine((String("当前声音强度:") + String((sound.read()))));
	delay(1000);
	if (((sound.read())>100)) {
		rgb.write(-1, 0x0000FF);
		display.setCursorLine(2);
		display.printLine("灯已打开");
	}
	else {
		rgb.write(-1, 0x000000);
		display.setCursorLine(2);
		display.printLine("灯已关闭");
	}
}

实验效果图:
在这里插入图片描述

在这里插入图片描述
【实验三】语音识别控制灯
核心代码截图:
在这里插入图片描述
C语言代码:

#include <MPython.h>
#include <DFRobot_Iot.h>
#include <MPython_ASR.h>
// 创建对象
DFRobot_Iot myIot;
MPython_ASR mpythonAsr;
String      str_mpythonAsr_result;

// 主程序开始
void setup() {
	mPython.begin();
	display.setCursorLine(1);
	display.printLine("开始连接WiFi");
	myIot.wifiConnect("Huang", "Huang123456.");
	while (!myIot.wifiStatus()) {yield();}
	display.setCursorLine(1);
	display.printLine("Wifi连接成功");
}
void loop() {
	display.setCursorLine(2);
	display.printLine("语音识别中...");
	str_mpythonAsr_result=mpythonAsr.getAsrResult(2);
	display.setCursorLine(3);
	display.printLine((str_mpythonAsr_result));
	delay(100);
	if (((String(str_mpythonAsr_result).indexOf(String("开灯")) != -1))) {
		rgb.write(-1, 0xFFFF00);
	}
	delay(100);
	if (((String(str_mpythonAsr_result).indexOf(String("关灯")) != -1))) {
		rgb.write(-1, 0x000000);
	}
	display.fillInLine(2, 0);
	delay(1000);
}

实验效果图:
在这里插入图片描述
在这里插入图片描述

【实验四】实现Easy IoT上mqtt消息的通讯
核心代码截图:
甲实验代码:
在这里插入图片描述
C语言代码:

#include <MPython.h>
#include <DFRobot_Iot.h>
// 函数声明
void onButtonAPressed();
void obloqMqttEventT0(String& message);
// 静态常量
const String topics[5] = {"6ablb9OGR","1vY_x9dMg","","",""};
const MsgHandleCb msgHandles[5] = {obloqMqttEventT0,NULL,NULL,NULL,NULL};
// 创建对象
DFRobot_Iot myIot;

// 主程序开始
void setup() {
	mPython.begin();
	myIot.setMqttCallback(msgHandles);
	buttonA.setPressedCallback(onButtonAPressed);
	display.setCursorLine(1);
	display.printLine("开始连接WiFi");
	myIot.wifiConnect("Huang", "Huang123456.");
	while (!myIot.wifiStatus()) {yield();}
	display.setCursorLine(1);
	display.printLine("Wifi连接成功");
	myIot.init("iot.dfrobot.com.cn","aETlbrdGR","","-Po_x9dGRz",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);
}

乙实验代码:
在这里插入图片描述
C语言代码:

#include <MPython.h>
#include <DFRobot_Iot.h>
// 函数声明
void onButtonBPressed();
void obloqMqttEventT1(String& message);
// 静态常量
const String topics[5] = {"6ablb9OGR","1vY_x9dMg","","",""};
const MsgHandleCb msgHandles[5] = {NULL,obloqMqttEventT1,NULL,NULL,NULL};
// 创建对象
DFRobot_Iot myIot;
// 主程序开始
void setup() {
	mPython.begin();
	myIot.setMqttCallback(msgHandles);
	buttonB.setPressedCallback(onButtonBPressed);
	display.setCursorLine(1);
	display.printLine("开始连接WiFi");
	myIot.wifiConnect("Huang", "Huang123456.");
	while (!myIot.wifiStatus()) {yield();}
	display.setCursorLine(1);
	display.printLine("Wifi连接成功");
	myIot.init("iot.dfrobot.com.cn","aETlbrdGR","","-Po_x9dGRz",topics,1883);
	myIot.connect();
	while (!myIot.connected()) {yield();}
	display.setCursorLine(2);
	display.printLine("MQTT连接成功");
}
void loop() {
}
// 事件回调函数
void onButtonBPressed() {
	myIot.publish(topic_0, "陈心辉已收到");
	display.setCursorLine(4);
	display.printLine("陈心辉发送成功");
}
void obloqMqttEventT1(String& message) {
	display.setCursorLine(3);
	display.printLine(message);
}

实验效果图:
WiFi、MQTTl连接:
在这里插入图片描述
甲按A键发送消息至topic1:
在这里插入图片描述
乙监听topic1:
在这里插入图片描述
乙接受到甲的消息后按B键回复消息给topic0:
在这里插入图片描述
甲监听topic0:
在这里插入图片描述

实验结论与体会

  1. 通过本次实验,学会了使用mind+来实验光控灯、声控灯、语音控制灯和Easy IoT上mqtt消息的通讯。
  2. 通过本次实验,使我对mind+图形化编程的用法了解更深一步。
  3. 通过过本次实验,使我对mind+和掌控板的基础知识了解更深一步,也提高了自已在硬件方面的动手能力。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Huang_xianlong

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值