hc-12无线串口运用与矩阵映射
-
如何使用hc-12无线串口,实现小车与电脑的无线通讯,串口的矩阵映射如何实现?```
#include <Arduino.h>
#include <Esp32McpwmMotor.h>
#include <Esp32PcntEncoder.h>
#include "PidController.h"
#include <HardwareSerial.h>// #define HC_RX 37 // UART2的RX引脚
// #define HC_TX 38 // UART2的TX引脚// HardwareSerial HC12(2);
Esp32McpwmMotor motor;
Esp32PcntEncoder encoders[4];
PidController pid_controller[4];// 运动控制参数
const float wheel_diameter = 0.065;
const float pulses_per_rev = 1978.0f;
const float wheel_circumference = PI * wheel_diameter;
const float pulse_distance = wheel_circumference / pulses_per_rev;
const float wheel_base = 0.188f;enum MotionState { STOPPED, MOVING_FORWARD, MOVING_BACKWARD, ROTATING }; // 新增后退状态
MotionState currentState = STOPPED;unsigned long stopStartTime = 0;
int currentCommand = 0;
int taskStep = 0;
int64_t initial_ticks[4] = {0};
float target_distance = 0;
float target_angle = 0;void setup() {
// Serial.begin(115200);
Serial.begin(9600,SERIAL_8N1,37,38);
// HC12.begin(9600, SERIAL_8N1, HC_RX, HC_TX); -
-
@lin_nyy 建议他先搞一个USB转TTL的模块,先调试一下串口通信是否正常