Performance Arduino电机速度和方向

Performance Arduino电机速度和方向,performance,bluetooth,arduino,Performance,Bluetooth,Arduino,我想制作一个程序来控制我的Arduino蓝牙汽车。 我有很多困难,使它在一个理想的方向,在一个理想的速度。到目前为止,我尝试过这个方法,但由于某些原因,它不起作用: int motor1clock=7,motor1clock=8,pwm1=3,pwm2=9,motor2clock=10,motor2clocko=16,速度; 字符串inputString=“”,垃圾; 无效设置() { 引脚模式(电机1锁定,输出); pinMode(电机锁定,输出); 引脚模式(pwm1,输出); pinMod

我想制作一个程序来控制我的Arduino蓝牙汽车。
我有很多困难,使它在一个理想的方向,在一个理想的速度。到目前为止,我尝试过这个方法,但由于某些原因,它不起作用:

int motor1clock=7,motor1clock=8,pwm1=3,pwm2=9,motor2clock=10,motor2clocko=16,速度;
字符串inputString=“”,垃圾;
无效设置()
{
引脚模式(电机1锁定,输出);
pinMode(电机锁定,输出);
引脚模式(pwm1,输出);
pinMode(电机锁定,输出);
引脚模式(电机2锁定,输出);
pinMode(pwm2,输出);
Serial1.begin(9600);
}
无效远期(国际特快专递)
{
模拟写入(pwm2、spee);
模拟写入(pwm1,spee);
数字写入(电机1锁定,低电平);
数字写入(motor1clockc,高);
数字写入(motor2clocko,高);
数字写入(电机2锁定,低电平);
}
向后作废(int spee)
{
模拟写入(pwm2、spee);
模拟写入(pwm1,spee);
数字写入(电机1锁,高);
数字写入(MOTOR1CLOCK,低电平);
数字写入(motor2clocko,低电平);
数字写入(电机2锁,高);
}
左转向无效(内部速度)
{
模拟写入(pwm2,spee-20);
模拟写入(pwm1,spee);
数字写入(电机1锁定,低电平);
数字写入(motor1clockc,高);
数字写入(motor2clocko,低电平);
数字写入(电机2锁,高);
}
右转向无效(内部速度)
{
模拟写入(pwm2、spee);
模拟写入(pwm1,spee-20);
数字写入(电机1锁,高);
数字写入(MOTOR1CLOCK,低电平);
数字写入(motor2clocko,高);
数字写入(电机2锁定,低电平);
}
void循环()
{
如果(Serial1.available()>0){
String str=Serial1.readString();
半英寸[3];
托查拉里街(英查,3);
while(Serial1.available()>0){
junk=Serial1.readString();
}
int num=atoi(&inChar[1]);
速度=num;
Serial1.println(速度);
如果(英寸[0]=“A”){
Serial1.println(英寸[0]);
前进(速度);
}
如果(英寸[0]=“B”){
向后(速度);
}
如果(英寸[0]=“C”){
向左转向(速度);
}
如果(英寸[0]='D'){
右转向(速度);
}
如果(英寸[0]!=“A”|英寸[0]!=“B”|英寸[0]!=“C”|英寸[0]!=“D”){
数字写入(电机1锁定,低电平);
数字写入(MOTOR1CLOCK,低电平);
数字写入(motor2clocko,低电平);
数字写入(电机2锁定,低电平);
}
inputString=“”;
}
}

输入代码格式为“命令速度”,例如:“A255”。

字符串“A255”中有3个以上的字节,因此我建议您定义inChar[6]。
而且,“Serial1.println(speed);”是否打印所需的速度?

除了尝试将5个字符(字符串长度+空终止符)放入3个字符的数组中之外,还有1秒的延迟。通过发送行和使用来修复它。另外,“不工作”也不是一个很好的问题描述。