有兴趣可以点击**我的店铺**看看小车硬件。提供安装说明。此图片仅供参考,图中是2驱超声波避障+循迹双模式小车。程序与本文有相同之处。
。。。。。。。。。。。。。。。。。。。。
四驱arduino超声波+红外线避障小车。以下是我优化后的代码
#include <Servo.h>
int pinLB = 5; //左退
int pinLF = 4; //左前
int pinRB = 3; //右退
int pinRF = 2; //右前
int inputPin = A0;//超声波Echo引脚
int outputPin = A1; //超声波Trig引脚
int servoPin = 13; //舵机信息号引脚
const int SensorLeft = 7; //左红外传感器管引脚
const int SensorRight = 8; //右红外传感器管引脚
int MotorRPWM=6;
int MotorLPWM=11;
int SL; //左
int SR; //右
int Fspeedd = 0;
int Rspeedd = 0;
int Lspeedd = 0;
int directionn = 0;
Servo myservo;//定义舵机
int delay_time = 250;
int Fgo = 1;
int Rgo = 2;
int Lgo = 3;
int Bgo = 4;
int F = 90;
int L1 = 170;
int L2 = 130;
int R1 = 10;
int R2 = 50;
int F_space = 0;
int Stime = 0;//转向用时
int L_space = 0;
int L1_space = 0;
int L2_space