触摸显示数字并亮灯
材料:掌控板、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
制作过程: