How to Program the Soccer Bot

This lesson will go over how to program the Soccer Bot

What it does

The Soccer Robot can be controlled using a remote controller; it can move forward and backward and also turn to the right and left.

Objective

Program the controller in such a way that:

  1. If up is pressed, move forward.
  2. If down is pressed, move backward.
  3. If left is pressed, turn left.
  4. If right is pressed, turn right.
  5. Otherwise, stop.

Now we need to work on the setup code. We need to include the SmartInventor library to pull in all of the background files. Then since we are using the motors and the remote we will need to set both of them up.

Next in void loop we will read the remote and save which button is pressed to allow us to check later.

Now it is time to write the main section of the code. In order to do so, an “if statement” may be used to check whether any of controller buttons have been pressed.

The following statement checks whether the up button has been pressed. If it is, it will drive forward.

Similarly for when down, left, or right buttons are pressed, we will move accordingly:

Then in the case when no buttons are pressed, the following can be used to bring the motor to a slow stop:

Optional: In order to customize the robot’s actions, the motor speed or the delay time may be changed accordingly.

Final Code