So the code looks like this:
//pin setup
const int Motor1Pin1 = 8;
const int Motor1Pin2 = 9;
const int Motor2Pin1 = 10;
const int Motor2Pin2 = 11;
const int LeftGreenLed = 6;
const int LeftYellowLed = 13;
const int RightGreenLed = 7;
const int RightYellowLed = 12;
//IO setup
void setup() {
pinMode(Motor1Pin1, OUTPUT);
pinMode(Motor1Pin2, OUTPUT);
pinMode(Motor2Pin1, OUTPUT);
pinMode(Motor2Pin2, OUTPUT);
pinMode(LeftGreenLed, OUTPUT);
pinMode(LeftYellowLed, OUTPUT);
pinMode(RightGreenLed, OUTPUT);
pinMode(RightYellowLed, OUTPUT);
}
//my loop
void loop() {
int czas = 6000;//time the robot is moving forward
digitalWrite(LeftGreenLed, HIGH);
digitalWrite(RightGreenLed, HIGH);
digitalWrite(LeftYellowLed, LOW);
digitalWrite(RightYellowLed, LOW);
GoForward();
delay(czas);
Stop();
delay(1000);
digitalWrite(LeftYellowLed, HIGH);
digitalWrite(RightYellowLed, HIGH);
digitalWrite(LeftGreenLed, LOW);
digitalWrite(RightGreenLed, LOW);
GoRight();
delay(800);
Stop();
delay(1000);
}
//forward
void GoForward(){
digitalWrite(Motor1Pin2, LOW);
digitalWrite(Motor1Pin1, HIGH);
digitalWrite(Motor2Pin2, LOW);
digitalWrite(Motor2Pin1, HIGH);
}
//backward
void GoBackward(){
digitalWrite(Motor1Pin1, LOW);
digitalWrite(Motor1Pin2, HIGH);
digitalWrite(Motor2Pin1, LOW);
digitalWrite(Motor2Pin2, HIGH);
}
//turn left
void GoLeft(){
digitalWrite(Motor1Pin1, LOW);
digitalWrite(Motor1Pin2, HIGH);
digitalWrite(Motor2Pin2, LOW);
digitalWrite(Motor2Pin1, HIGH);
}
//turn right
void GoRight(){
digitalWrite(Motor1Pin2, LOW);
digitalWrite(Motor1Pin1, HIGH);
digitalWrite(Motor2Pin1, LOW);
digitalWrite(Motor2Pin2, HIGH);
}
//robot stop
void Stop(){
digitalWrite(Motor1Pin2, LOW);
digitalWrite(Motor1Pin1, LOW);
digitalWrite(Motor2Pin1, LOW);
digitalWrite(Motor2Pin2, LOW);
}
Thank you in advance.
I know the code has extra commands for movement but I'd like to use them in the future so this is a universal starting code.