很多遥控小车都是用PS2手柄,红外遥控器之类的来遥控。我这个程序不一样,他是用掌控板来遥控。
- /*!
- * MindPlus
- * mpython
- *
- */
- #include <MPython.h>
- #include <IOBOX_Motor.h>
- #include <DFRobot_ESP32_Radio.h>
-
- // 动态变量
- volatile float mind_n_Whether_to_start_or_not;
- // 函数声明
- void onRadioReceive_0();
- void onRadioReceive(String message);
- // 创建对象
- DFRobot_ESP32Radio Radio;
- IOBOX_Motor motor_ib;
-
-
- // 主程序开始
- void setup() {
- Radio.setCallback("OK", onRadioReceive_0);
- mPython.begin();
- Radio.setCallback(onRadioReceive);
- display.fillScreen(0);
- mind_n_Whether_to_start_or_not = 0;
- Radio.turnOn();
- Radio.setGroup(1);
- Radio.send("GO");
- }
- void loop() {
-
- }
-
- // 事件回调函数
- void onRadioReceive_0() {
- mind_n_Whether_to_start_or_not = 1;
- display.setCursorLine(1);
- display.printLine("待命中...");
- display.setCursorLine(2);
- display.printLine("随时准备出发");
- }
- void onRadioReceive(String message) {
- display.fillScreen(1);
- if ((mind_n_Whether_to_start_or_not==1)) {
- if (((String(message).length())==2)) {
- // 左转
- motor_ib.motorRun(motor_ib.M1, motor_ib.CW, 200);
- motor_ib.motorRun(motor_ib.M2, motor_ib.CW, 140);
- }
- if (((String(message).length())==3)) {
- // 右转
- motor_ib.motorRun(motor_ib.M2, motor_ib.CW, 200);
- motor_ib.motorRun(motor_ib.M1, motor_ib.CW, 140);
- }
- if (((String(message).length())==1)) {
- motor_ib.motorRun(motor_ib.M2, motor_ib.CW, 255);
- motor_ib.motorRun(motor_ib.M1, motor_ib.CW, 255);
- }
- }
- }
复制代码
|
算了吧,直接告诉你们吧。
[code]/*!
* MindPlus
* mpython
*
*/
#include
#include
// 函数声明
void onRadioReceive_0();
// 创建对象
DFRobot_ESP32Radio Radio;
// 主程序开始
void setup() {
Radio.setCallback("GO", onRadioReceive_0);
mPython.begin();
Radio.turnOn();
Radio.setGroup(1);
}
void loop() {
}
// 事件回调函数
void onRadioReceive_0() {
Radio.send("OK");
while (1) {
if ((buttonA.isPressed())) {
Radio.send("ZZ");
}
if ((buttonB.isPressed())) {
Radio.send("YZB");
}
if ((buttonAB.isPressed())) {
Radio.send("Z");
}
yield();
}
}
[/code]