Hello, I have set up the elegoo smart car kit. I have successfully loaded the "auto_go" program and the car now drives forward and backward.
I am now trying to use the "auto_go" program from the arduino library to simply move the car forward then stop after approximately 3 seconds (It is for a different project using the same code). I have successfully cancelled the pauses to move forward and backward, however I simply want the forward motion to stop. How do I insert a stop function? Below is as far as I got with the code:
/ The direction of the car's movement
// ENA ENB IN1 IN2 IN3 IN4 Description
// HIGH HIGH HIGH LOW LOW HIGH Car is runing forward
// HIGH HIGH LOW HIGH HIGH LOW Car is runing back
// HIGH HIGH LOW HIGH LOW HIGH Car is turning left
// HIGH HIGH HIGH LOW HIGH LOW Car is turning right
// HIGH HIGH LOW LOW LOW LOW Car is stoped
// HIGH HIGH HIGH HIGH HIGH HIGH Car is stoped
// LOW LOW N/A N/A N/A N/A Car is stoped
//define L298n module IO Pin
#define ENB 5
#define IN1 7
#define IN2 8
#define IN3 9
#define IN4 11
#define ENA 6
void forward(){
digitalWrite(ENA, HIGH); //enable L298n A channel
digitalWrite(ENB, HIGH); //enable L298n B channel
digitalWrite(IN1, HIGH); //set IN1 hight level
digitalWrite(IN2, LOW); //set IN2 low level
digitalWrite(IN3, LOW); //set IN3 low level
digitalWrite(IN4, HIGH); //set IN4 hight level
Serial.println("Forward"); //send message to serial monitor
}
//before execute loop() function,
//setup() function will execute first and only execute once
void setup() {
Serial.begin(9600); //open serial and set the baudrate
pinMode(IN1, OUTPUT); //before useing io pin, pin mode must be set first
pinMode(IN2, OUTPUT);
pinMode(IN3, OUTPUT);
pinMode(IN4, OUTPUT);
pinMode(ENA, OUTPUT);
pinMode(ENB, OUTPUT);
}
//Repeat execution
void loop() {
forward(); //go forward
delay(100); //delay 100 ms
}