2022-2-28 15:32:32 [显示全部楼层]
21212浏览
查看: 21212|回复: 3

[项目] 掌控板遥控小车

[复制链接]
本帖最后由 RYAN 于 2022-2-28 17:17 编辑

很多遥控小车都是用PS2手柄,红外遥控器之类的来遥控。我这个程序不一样,他是用掌控板来遥控。
  1. /*!
  2. * MindPlus
  3. * mpython
  4. *
  5. */
  6. #include <MPython.h>
  7. #include <IOBOX_Motor.h>
  8. #include <DFRobot_ESP32_Radio.h>
  9. // 动态变量
  10. volatile float mind_n_Whether_to_start_or_not;
  11. // 函数声明
  12. void onRadioReceive_0();
  13. void onRadioReceive(String message);
  14. // 创建对象
  15. DFRobot_ESP32Radio Radio;
  16. IOBOX_Motor        motor_ib;
  17. // 主程序开始
  18. void setup() {
  19.         Radio.setCallback("OK", onRadioReceive_0);
  20.         mPython.begin();
  21.         Radio.setCallback(onRadioReceive);
  22.         display.fillScreen(0);
  23.         mind_n_Whether_to_start_or_not = 0;
  24.         Radio.turnOn();
  25.         Radio.setGroup(1);
  26.         Radio.send("GO");
  27. }
  28. void loop() {
  29. }
  30. // 事件回调函数
  31. void onRadioReceive_0() {
  32.         mind_n_Whether_to_start_or_not = 1;
  33.         display.setCursorLine(1);
  34.         display.printLine("待命中...");
  35.         display.setCursorLine(2);
  36.         display.printLine("随时准备出发");
  37. }
  38. void onRadioReceive(String message) {
  39.         display.fillScreen(1);
  40.         if ((mind_n_Whether_to_start_or_not==1)) {
  41.                 if (((String(message).length())==2)) {
  42.                         // 左转
  43.                         motor_ib.motorRun(motor_ib.M1, motor_ib.CW, 200);
  44.                         motor_ib.motorRun(motor_ib.M2, motor_ib.CW, 140);
  45.                 }
  46.                 if (((String(message).length())==3)) {
  47.                         // 右转
  48.                         motor_ib.motorRun(motor_ib.M2, motor_ib.CW, 200);
  49.                         motor_ib.motorRun(motor_ib.M1, motor_ib.CW, 140);
  50.                 }
  51.                 if (((String(message).length())==1)) {
  52.                         motor_ib.motorRun(motor_ib.M2, motor_ib.CW, 255);
  53.                         motor_ib.motorRun(motor_ib.M1, motor_ib.CW, 255);
  54.                 }
  55.         }
  56. }
复制代码

RYAN  初级技师
 楼主|

发表于 2022-2-28 15:33:56

本帖最后由 RYAN 于 2022-2-28 17:31 编辑

遥控端的程序想看吗?想看就回复666
算了吧,直接告诉你们吧。
  1. /*!
  2. * MindPlus
  3. * mpython
  4. *
  5. */
  6. #include <MPython.h>
  7. #include <DFRobot_ESP32_Radio.h>
  8. // 函数声明
  9. void onRadioReceive_0();
  10. // 创建对象
  11. DFRobot_ESP32Radio Radio;
  12. // 主程序开始
  13. void setup() {
  14.         Radio.setCallback("GO", onRadioReceive_0);
  15.         mPython.begin();
  16.         Radio.turnOn();
  17.         Radio.setGroup(1);
  18. }
  19. void loop() {
  20. }
  21. // 事件回调函数
  22. void onRadioReceive_0() {
  23.         Radio.send("OK");
  24.         while (1) {
  25.                 if ((buttonA.isPressed())) {
  26.                         Radio.send("ZZ");
  27.                 }
  28.                 if ((buttonB.isPressed())) {
  29.                         Radio.send("YZB");
  30.                 }
  31.                 if ((buttonAB.isPressed())) {
  32.                         Radio.send("Z");
  33.                 }
  34.                 yield();
  35.         }
  36. }
复制代码

回复

使用道具 举报

rzyzzxw  版主

发表于 2022-3-2 19:10:41

RYAN 发表于 2022-2-28 15:33
遥控端的程序想看吗?想看就回复666
算了吧,直接告诉你们吧。

666
回复

使用道具 举报

小企鹅  初级技匠

发表于 2022-3-17 18:13:44

666厉害厉害
回复

使用道具 举报

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

本版积分规则

为本项目制作心愿单
购买心愿单
心愿单 编辑
[[wsData.name]]

硬件清单

  • [[d.name]]
btnicon
我也要做!
点击进入购买页面
上海智位机器人股份有限公司 沪ICP备09038501号-4

© 2013-2024 Comsenz Inc. Powered by Discuz! X3.4 Licensed

mail