37创客科创中心

 找回密码
 立即注册
查看: 1570|回复: 4

20240420 小学组

  [复制链接]

194

主题

324

帖子

2399

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
2399
发表于 2024-4-20 02:04:32 | 显示全部楼层 |阅读模式

下载mind+编程软件
https://download3.dfrobot.com.cn/MindPlus_Win_V1.8.0_RC3.1.exe

服务器2个版本一致;主题:37ck/419
1:用户名:37ck   密码:20200808   端口:1884
2:用户名:37ck  密码:dfrobot        端口:1883

使用到的扩展:
主控板:掌控板
网络服务:wifi、MQTT
扩展板:麦昆扩展板



本程序实现物联网多版本切换;
红外线控制麦昆;
麦昆巡线;


本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x
回复

使用道具 举报

194

主题

324

帖子

2399

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
2399
 楼主| 发表于 2024-4-20 02:09:54 | 显示全部楼层
开启网路记录
回复

使用道具 举报

194

主题

324

帖子

2399

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
2399
 楼主| 发表于 2024-4-20 02:10:44 | 显示全部楼层
  1. /*!
  2. * MindPlus
  3. * mpython
  4. *
  5. */
  6. #include <MPython.h>
  7. #include <DFRobot_Iot.h>
  8. #include <Maqueen_Motor.h>
  9. #include <DFRobot_IRremote.h>

  10. // 动态变量
  11. volatile float mind_n_L, mind_n_R;
  12. // 函数声明
  13. void onButtonAPressed();
  14. void onButtonBPressed();
  15. void DF_MQTT(String mind_s_WIFI, String mind_s_PWD, float mind_n_N);
  16. void DF_RUN(String mind_s_TZhiLing, float mind_n_NSuDu);
  17. void DF_XunXian(float mind_n_NSuDu);
  18. void onIRReceive(uint8_t data);
  19. void DF_MQTTBanBen(float mind_n_N);
  20. void DF_HongWaiZhuanMa(float mind_n_NBianMa, float mind_n_NSuDu);
  21. void obloqMqttEventTrxy91(String& message);
  22. // 静态常量
  23. const String topics[5] = {"37ck/419","","","",""};
  24. const MsgHandleCb msgHandles[5] = {obloqMqttEventTrxy91,NULL,NULL,NULL,NULL};
  25. // 创建对象
  26. DFRobot_Iot      myIot;
  27. Maqueen_Motor    motor_mq;
  28. IRremote_Receive remoteReceive_P16;


  29. // 主程序开始
  30. void setup() {
  31.         mPython.begin();
  32.         myIot.setMqttCallback(msgHandles);
  33.         buttonA.setPressedCallback(onButtonAPressed);
  34.         buttonB.setPressedCallback(onButtonBPressed);
  35.         remoteReceive_P16.begin(P16);
  36.         remoteReceive_P16.setCallback(onIRReceive);
  37.         DF_MQTT("37ck", "20200808", 1);
  38. }
  39. void loop() {

  40. }

  41. // 自定义函数
  42. void DF_MQTT(String mind_s_WIFI, String mind_s_PWD, float mind_n_N) {
  43.         display.setCursorLine(1);
  44.         display.printLine("WIFI...");
  45.         myIot.wifiConnect(mind_s_WIFI, mind_s_PWD);
  46.         while (!myIot.wifiStatus()) {yield();}
  47.         display.setCursorLine(1);
  48.         display.printLine(myIot.getWiFiLocalIP());
  49.         display.setCursorLine(2);
  50.         display.printLine(myIot.getDNS());
  51.         DF_MQTTBanBen(mind_n_N);
  52. }
  53. void DF_RUN(String mind_s_TZhiLing, float mind_n_NSuDu) {
  54.         if (((String(mind_s_TZhiLing).indexOf(String("前进")) != -1))) {
  55.                 motor_mq.motorRun(motor_mq.LEFT,motor_mq.CW,mind_n_NSuDu);
  56.                 motor_mq.motorRun(motor_mq.RIGHT,motor_mq.CW,mind_n_NSuDu);
  57.         }
  58.         else if (((String(mind_s_TZhiLing).indexOf(String("右转")) != -1))) {
  59.                 motor_mq.motorRun(motor_mq.LEFT,motor_mq.CW,mind_n_NSuDu);
  60.                 motor_mq.motorRun(motor_mq.RIGHT,motor_mq.CW,0);
  61.         }
  62.         else if (((String(mind_s_TZhiLing).indexOf(String("左转")) != -1))) {
  63.                 motor_mq.motorRun(motor_mq.LEFT,motor_mq.CW,0);
  64.                 motor_mq.motorRun(motor_mq.RIGHT,motor_mq.CW,mind_n_NSuDu);
  65.         }
  66.         else if (((String(mind_s_TZhiLing).indexOf(String("后退")) != -1))) {
  67.                 motor_mq.motorRun(motor_mq.LEFT,motor_mq.CCW,mind_n_NSuDu);
  68.                 motor_mq.motorRun(motor_mq.RIGHT,motor_mq.CCW,mind_n_NSuDu);
  69.         }
  70.         else if (((String(mind_s_TZhiLing).indexOf(String("开灯")) != -1))) {
  71.                 rgb.write(-1, 0x0000FF);
  72.         }
  73.         else if (((String(mind_s_TZhiLing).indexOf(String("关灯")) != -1))) {
  74.                 rgb.write(-1, 0x000000);
  75.         }
  76.         else {
  77.                 motor_mq.motorRun(motor_mq.LEFT,motor_mq.CW,0);
  78.                 motor_mq.motorRun(motor_mq.RIGHT,motor_mq.CW,0);
  79.         }
  80. }
  81. void DF_XunXian(float mind_n_NSuDu) {
  82.         mind_n_L = digitalRead(P13);
  83.         mind_n_R = digitalRead(P14);
  84.         display.setCursorLine(2);
  85.         display.printLine(mind_n_L);
  86.         display.setCursorLine(3);
  87.         display.printLine(mind_n_R);
  88.         if (((mind_n_L==0) && (mind_n_R==0))) {
  89.                 DF_RUN("前进", mind_n_NSuDu);
  90.         }
  91.         else if (((mind_n_L==1) && (mind_n_R==0))) {
  92.                 DF_RUN("右转", mind_n_NSuDu);
  93.         }
  94.         else if (((mind_n_L==0) && (mind_n_R==1))) {
  95.                 DF_RUN("左转", mind_n_NSuDu);
  96.         }
  97.         else if (((mind_n_L==1) && (mind_n_R==1))) {
  98.                 DF_RUN("后退", mind_n_NSuDu);
  99.         }
  100.         else {
  101.         }
  102. }
  103. void DF_MQTTBanBen(float mind_n_N) {
  104.         display.setCursorLine(3);
  105.         display.printLine(mind_n_N);
  106.         if ((mind_n_N==2)) {
  107.                 myIot.init("i.37ck.cn","37ck","7344603147218602","dfrobot", topics, 1883);
  108.         }
  109.         else {
  110.                 myIot.init("i.37ck.cn","37ck","40792077618307276","20200808", topics, 1884);
  111.         }
  112.         myIot.connect();
  113.         display.setCursorLine(1);
  114.         display.printLine("MQTT...");
  115.         while (!myIot.connected()) {yield();}
  116.         display.setCursorLine(1);
  117.         display.printLine("MQTT OK");
  118.         display.setCursorLine(4);
  119.         display.printLine("版本切换完成");
  120. }
  121. void DF_HongWaiZhuanMa(float mind_n_NBianMa, float mind_n_NSuDu) {
  122.         if ((mind_n_NBianMa==47)) {
  123.                 DF_RUN("前进", mind_n_NSuDu);
  124.         }
  125.         else if ((mind_n_NBianMa==119)) {
  126.                 DF_RUN("右转", mind_n_NSuDu);
  127.         }
  128.         else if ((mind_n_NBianMa==247)) {
  129.                 DF_RUN("左转", mind_n_NSuDu);
  130.         }
  131.         else if ((mind_n_NBianMa==143)) {
  132.                 DF_RUN("后退", mind_n_NSuDu);
  133.         }
  134.         else if ((mind_n_NBianMa==79)) {
  135.                 DF_RUN("停止", 1);
  136.         }
  137. }

  138. // 事件回调函数
  139. void onButtonAPressed() {
  140.         myIot.publish(topic_0, "开灯", 1);
  141.         delay(2000);
  142.         myIot.publish(topic_0, "关灯", 1);
  143. }
  144. void onButtonBPressed() {
  145.         myIot.publish(topic_0, "开灯");
  146.         delay(2000);
  147.         myIot.publish(topic_0, "关灯");
  148. }
  149. void onIRReceive(uint8_t data) {
  150.         display.setCursorLine(2);
  151.         display.printLine(data);
  152.         DF_HongWaiZhuanMa(data, 160);
  153. }
  154. void obloqMqttEventTrxy91(String& message) {
  155.         display.setCursorLine(4);
  156.         display.printLine(message);
  157.         if (((String(message).indexOf(String("MQTT1")) != -1))) {
  158.                 DF_MQTT("37ck", "20200808", 1);
  159.         }
  160.         else if (((String(message).indexOf(String("MQTT2")) != -1))) {
  161.                 DF_MQTT("37ck", "20200808", 2);
  162.         }
  163.         else if (((String(message).indexOf(String("巡线")) != -1))) {
  164.                 DF_XunXian(150);
  165.         }
  166.         else {
  167.                 DF_RUN(message, 160);
  168.         }
  169. }
复制代码
回复

使用道具 举报

194

主题

324

帖子

2399

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
2399
 楼主| 发表于 2024-4-20 02:11:26 | 显示全部楼层
代码部分需要进行端口修改
回复

使用道具 举报

194

主题

324

帖子

2399

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
2399
 楼主| 发表于 2024-4-20 10:41:26 | 显示全部楼层
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|手机版|小黑屋|37创客科创中心

GMT+8, 2025-12-10 06:00 , Processed in 0.164398 second(s), 19 queries .

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表