Now we need to write some code. Don't worry, we'll start with some simple stuff.

You only have two know four different commands:

  1. forward
  2. back
  3. right
  4. left

I'll let you guess what each of the commands does.

In the Arduino programming language, a function name will be followed by parentheses. Inside the parentheses, you often will give some kind of input value. Like this:

forward(2)

For this function, the input value is how many seconds you want it to follow that command. So, in this case, it will go forward for 2 seconds.

Each line needs to end with a semicolon (;), like this:

forward(2);

If you skip the semicolon, you will get an error.

There's one final thing you'll need to know to get your code working properly. All of your commands should go in the setup function, like this:

void setup() {
  // Write your code here:
  forward(2);
  right(3);
  left(3);
  back(2);
}

So start by just typing in forward(2); in the setup block. Then hit the upload button (it's the one that looks like an arrow pointing to the right).

NavEPWL.png

Did it go forward? If not, which wheel went the wrong way? To fix this, try swapping the red and black wires from the motor into the motor controller.

Just to be complete, here is the full code. I wrote all the stuff after the setup function to make everything cleaner. But I hid it all at the end.

void setup() {
  // Write your code here:
  forward(2);
  right(3);
  left(3);
  back(2);
}
 
int rightEN = A0;
int leftEN = A5;
int rightFwd = A1;
int rightBack =  A2;
int leftFwd = A3;
int leftBack = A4;
 
void forward(float driveTime){
  digitalWrite(rightEN, HIGH);
  digitalWrite(leftEN, HIGH);
  digitalWrite(rightFwd, HIGH);
  digitalWrite(rightBack, LOW);
  digitalWrite(leftFwd, HIGH);
  digitalWrite(leftBack, LOW);
 
  delay(driveTime*1000);
 
  digitalWrite(rightEN, LOW);
  digitalWrite(leftEN, LOW);
}
 
void right(float driveTime){
  digitalWrite(rightEN, HIGH);
  digitalWrite(leftEN, HIGH);
  digitalWrite(rightFwd, LOW);
  digitalWrite(rightBack, HIGH);
  digitalWrite(leftFwd, HIGH);
  digitalWrite(leftBack, LOW);
 
  delay(driveTime*1000);
 
  digitalWrite(rightEN, LOW);
  digitalWrite(leftEN, LOW);
}
 
void left(float driveTime){
  digitalWrite(rightEN, HIGH);
  digitalWrite(leftEN, HIGH);
  digitalWrite(rightFwd, HIGH);
  digitalWrite(rightBack, LOW);
  digitalWrite(leftFwd, LOW);
  digitalWrite(leftBack, HIGH);
 
  delay(driveTime*1000);
 
  digitalWrite(rightEN, LOW);
  digitalWrite(leftEN, LOW);
}
 
void back(float driveTime){
  digitalWrite(rightEN, HIGH);
  digitalWrite(leftEN, HIGH);
  digitalWrite(rightFwd, LOW);
  digitalWrite(rightBack, HIGH);
  digitalWrite(leftFwd, LOW);
  digitalWrite(leftBack, HIGH);
 
  delay(driveTime*1000);
 
  digitalWrite(rightEN, LOW);
  digitalWrite(leftEN, LOW);
}
 
void loop() {
  //You dont need to put any code here.  
}