【Mind+】掌控板的触摸灯/mqtt篮球计分

触摸显示数字并亮灯

材料:掌控板、type-c 数据线一条
功能:触摸到p、y、t分别在第一、二、三行显示1、2、3,并分别亮起掌控板0、1、2号LED灯。
图形化代码:
在这里插入图片描述
C代码:

#include <MPython.h>
#include <DFRobot_Iot.h>
// 静态常量
const String topics[5] = {"LF1/1","LF2/2","LF3/3","",""};
// 创建对象
DFRobot_Iot myIot;


// 主程序开始
void setup() {
	mPython.begin();
	display.setCursor(0, 0);
	display.print("WIFI连接ing");
	myIot.wifiConnect("HONOR V20", "1234567890");
	while (!myIot.wifiStatus()) {yield();}
	display.fillScreen(0);
	display.setCursor(0, 0);
	display.print("WIFI已连接");
	myIot.init("192.168.43.68","602","","iot", topics, 1883);
	myIot.connect();
	while (!myIot.connected()) {yield();}
	display.fillScreen(0);
	display.setCursor(0, 0);
	display.print("mqtt连接成功");
	display.fillScreen(0);
	display.setCursorLine(4);
	display.printLine("2018A14116 刘烽");
}
void loop() {
	if ((touchPadP.isTouched())) {
		display.setCursorLine(1);
		display.printLine("1");
		rgb.write(0, 0x0000FF);
		while (!(!touchPadP.isTouched())) {yield();}
		display.fillInLine(1, 0);
		rgb.write(-1, 0x000000);
	}
	else if ((touchPadY.isTouched())) {
		display.setCursorLine(2);
		display.printLine("2");
		rgb.write(1, 0xFF0000);
		while (!(!touchPadY.isTouched())) {yield();}
		display.fillInLine(2, 0);
		rgb.write(-1, 0x000000);
	}
	else if ((touchPadT.isTouched())) {
		display.setCursorLine(3);
		display.printLine("3");
		rgb.write(2, 0xFF9900);
		while (!(!touchPadT.isTouched())) {yield();}
		display.fillInLine(3, 0);
		rgb.write(-1, 0x000000);
	}
}

演示视频:视频1

mqtt篮球计分板

材料:掌控板,type-c数据线一条
功能;通过自制的mqtt apk实现与掌控板的通信,当收到的topic信息值为0<x<=3时,分别加1、2、3分,除此外的值不显示也不累加。
图形化代码:
在这里插入图片描述
C代码:

#include <MPython.h>
#include <DFRobot_Iot.h>

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


// 主程序开始
void setup() {
	mPython.begin();
	myIot.setMqttCallback(msgHandles);
	myIot.wifiConnect("HONOR V20", "1234567890");
	display.setCursor(0, 0);
	display.print("WiFi连接ing...");
	while (!myIot.wifiStatus()) {yield();}
	display.fillScreen(0);
	display.setCursor(0, 0);
	display.print("WIFI已连接");
	myIot.init("192.168.43.68","602","","iot", topics, 1883);
	myIot.connect();
	while (!myIot.connected()) {yield();}
	display.fillScreen(0);
	display.setCursor(0, 0);
	display.print("mqtt连接成功");
	mind_n_DeFen = 0;
	display.setCursorLine(3);
	display.printLine((String("得分:") + String((String(mind_n_DeFen).toInt()))));
	display.setCursorLine(4);
	display.printLine("2018A14116 刘烽");
}
void loop() {

}

// 事件回调函数
void obloqMqttEventT0(String& message) {
	if (((String(message).toInt())==1)) {
		rgb.write(0, 0x0000FF);
		mind_n_DeFen += 1;
	}
	else if (((String(message).toInt())==2)) {
		rgb.write(1, 0xFF0000);
		mind_n_DeFen += 2;
	}
	else if (((String(message).toInt())==3)) {
		rgb.write(2, 0xFF9900);
		mind_n_DeFen += 3;
	}
	if ((((String(message).toInt())>=0) && ((String(message).toInt())<=3))) {
		display.setCursorLine(2);
		display.printLine((String("加分:") + String((String(message).toInt()))));
	}
	display.setCursorLine(3);
	display.printLine((String("得分:") + String((String(mind_n_DeFen).toInt()))));
	delay(3000);
	rgb.write(-1, 0x000000);
}

演示视频:视频2

关于手机app apk的制作:

页面样式:
在这里插入图片描述
制作工具:AppInventor2019PersonalEdition
制作过程:

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值