Home > Back-end >  Arduino car debugging is not successful
Arduino car debugging is not successful

Time:12-22

#include
//definition understanding motion state
# define STOP 0
# define FORWARD 1
# define BACKWARD 2
# define TURNLEFT 3
# define TURNRIGHT 4
//pin definition needed
Int leftMotor1=7;
Int leftMotor2=6;
Int rightMotor1=4;
Int rightMotor2=5;

Void setup () {
PinMode (leftMotor1, the OUTPUT);
PinMode (leftMotor2, the OUTPUT);
PinMode (rightMotor1, the OUTPUT);
PinMode (rightMotor2, the OUTPUT);
}

Void loop () {
//put your main code here, to run repeatedly:
int cmd;
For (CMD=0; Cmd<5; Cmd++)//in turn forward, backward, left, want to have to stop four motion state
{
MotorRun (CMD);
Delay (2000);//each command execution 2 s
}
}//motion control function
Void motorRun (int CMD)
{switch (CMD)
{
Case FORWARD:
DigitalWrite (leftMotor1, LOW);
DigitalWrite (leftMotor2, HIGH);
DigitalWrite (rightMotor1, LOW);
DigitalWrite (rightMotor2, HIGH);
Delay (1);
DigitalWrite (leftMotor1, LOW);
DigitalWrite (leftMotor2, LOW);
DigitalWrite (rightMotor1, LOW);
DigitalWrite (rightMotor2, LOW);
delay(10);
break;
Case BACKWARD:
DigitalWrite (leftMotor1, HIGH);
DigitalWrite (leftMotor2, LOW);
DigitalWrite (rightMotor1, HIGH);
DigitalWrite (rightMotor2, LOW);

Default: digitalWrite (leftMotor1, LOW);
DigitalWrite (leftMotor2, LOW);
DigitalWrite (rightMotor1, LOW);
DigitalWrite (rightMotor2, LOW);
}
}

Excuse me, what's the problem with this code, the car is not moving
  • Related