一、实验软硬件环境

硬件:掌控板

软件:Mind+

二、实验目的及要求

 

三、实验原理与内容

 

四、实验过程

首先我们先把掌控板和电脑连接起来之后进行代码编写:

1. 核心代码截图:

/*!
 * MindPlus
 * mpython
 *
 */
#include <MPython.h>


// 主程序开始
void setup() {
	mPython.begin();
	display.setCursorLine(4);
	display.printLine("2018A14126 蔡婉芬");
}
void loop() {
	if ((touchPadP.isTouched())) {
		display.setCursorLine(1);
		display.printLine("1");
		rgb.write(0, 0x0000FF);
		display.fillInLine(1, 0);
		rgb.write(-1, 0x000000);
	}
	else if ((touchPadY.isTouched())) {
		display.setCursorLine(2);
		display.printLine("2");
		rgb.write(0, 0xFFFF00);
		display.fillInLine(2, 0);
		rgb.write(-1, 0x000000);
	}
	else if ((touchPadT.isTouched())) {
		display.setCursorLine(3);
		display.printLine("3");
		rgb.write(0, 0xFF0000);
		display.fillInLine(3, 0);
		rgb.write(-1, 0x000000);
	}
}

c代码描述如上图

该效果视频如下:

掌控板 Mind+ 实验

 (2)

/*!
 * MindPlus
 * mpython
 *
 */
#include <MPython.h>
#include <DFRobot_Iot.h>

// 动态变量
volatile float mind_n_score;
// 函数声明
void obloqMqttEventT0(String& message);
// 静态常量
const String topics[5] = {"DFRobot/T0","DFRobot/T1","DFRobotT2","",""};
const MsgHandleCb msgHandles[5] = {obloqMqttEventT0,NULL,NULL,NULL,NULL};
// 创建对象
DFRobot_Iot myIot;


// 主程序开始
void setup() {
	mPython.begin();
	myIot.setMqttCallback(msgHandles);
	myIot.wifiConnect("rayne", "1234567a");
	while (!myIot.wifiStatus()) {yield();}
	display.setCursorLine(1);
	display.printLine(myIot.getWiFiLocalIP());
	myIot.init("192.168.43.253","602","","iot", topics, 1883);
	myIot.connect();
	while (!myIot.connected()) {yield();}
	display.setCursorLine(1);
	display.printLine("连接成功");
	mind_n_score = 0;
}
void loop() {

}

// 事件回调函数
void obloqMqttEventT0(String& message) {
	if (((String(message).indexOf(String("1")) != -1))) {
		mind_n_score += 1;
	}
	else if (((String(message).indexOf(String("2")) != -1))) {
		mind_n_score += 2;
	}
	else if (((String(message).indexOf(String("3")) != -1))) {
		mind_n_score += 3;
	}
	display.setCursorLine(1);
	display.printLine("2018A14126 蔡婉芬");
	display.setCursorLine(2);
	display.printLine((String("总分是") + String(mind_n_score)));
}

c代码描述如上图

该效果视频如下:

简易篮球计时器app

五、测试/调试及实验结果分析

测试成功!

 

六、实验结论与体会

通过这次实验,我了解到原来做App不一定要学会写代码,我们可以通过图形化实现,但是在实验过程中我遇到了一些问题,就是MQTT一直连接不了,找了好久还是没有找到问题所在,但是通过和同学相互探讨,可以不用使用MQTT也能实现结果。此外,我对掌控板也有了进一步的了解,原来掌控板不能与公网相连,不能使用5G的频段。

Logo

CSDN联合极客时间,共同打造面向开发者的精品内容学习社区,助力成长!

更多推荐