int STBY = 11; //standby
int PWMA = 3; //Speed control
int AIN1 = 23; //Direction
int AIN2 = 22; //Direction
int PWMB = 5; //Speed control
int BIN1 = 25; //Direction
int BIN2 = 24; //Direction
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
int i;
Serial.println("Hello World!");
if(Serial.available())
{
i=Serial.parseInt();
}
Serial.println(i,DEC);
switch(i)
{
case 2:
{
move(1,128,1);
move(2,128,1);
Serial.println("前进");
break;
}
case 4:
{
move(1,90,1);
move(2,90,0);
Serial.println("左转");
break;
}
case 6:
{
move(1,90,0);
move(2,90,1);
Serial.println("右转");
break;
}
case 8:
{
move(1,128,0);
move(2,128,0);
Serial.println("后退");
break;
}
case 5:
{
move(1,0,0);
move(2,0,0);
Serial.println("STOP!!!");
break;
}
}
}
void move(int motor, int speed, int direction){
digitalWrite(STBY, HIGH); //disable standby
boolean inPin1 = HIGH;
boolean inPin2 = LOW;
if(direction == 1){
inPin1 = LOW;
inPin2 = HIGH;
}
if(motor == 1){
digitalWrite(AIN1, inPin1);
digitalWrite(AIN2, inPin2);
analogWrite(PWMA, speed);
}
else{
digitalWrite(BIN1, inPin1);
digitalWrite(BIN2, inPin2);
analogWrite(PWMB, speed);
}
}这位板只有两个接口就每两个轮接在一起了,但是控制下车轮子动力不足,在地面上不走,但悬空可以。
跪求大佬!~~~~