How to Program the Gorilla Bot

This lesson will go over how to program the Gorilla Bot

What it Does

The Gorilla Robot can be controlled using a remote controller; it can move forward/backward/right/left and speed up/down.

Objectives

Program the controller in such a way that:

  1. If up/down is pressed, move forward/backward.
  2. If right/left is pressed, move right/left.
  3. If F1 is pressed speed up.
  4. If F2 is pressed slow down.
  5. If C is pressed move forward at full-speed.
  6. Otherwise, stop.

To customize this robot further, the LEDs may be used as indicators of the speed levels. Starting with the four middle LEDs (13, 14, 15, 16) turned on, a decrease or increase in the speed level can be determined by decreasing or increasing the number of on LEDs respectively.

We will start with our setup code. Firstly we need to include the SmartInventor library. Then since we are using the motors and the remote control, we will need to set them up too.

Next we are going to add in the LEDs, so we need to initializes those as both inputs and have the starting LEDs lit. We will also create the variable to keep track of our current speed.
Next in the loop we need to read the remote and save which button was pressed so that we can later check to see what was pressed.
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. (Reminder! Click here to review how “if statements” work). The following statements checks whether any of the buttons have been pressed (Reminder! Click here to review how to program the remote controller) and makes a corresponding movement.
In order to program any other buttons another “else if statement” may be added to the above code. For example, to associate the center key of the controller with the robot going fast forward, the following code may be used:
In the case when no buttons are pressed, the following else can be used to bring the motor to a slow stop:
In order to speed up or slow down the motors using F1 and F2 buttons, “if statements” must be used. In each case, the program must also check the speed before it increases or decreases the speed. This is to insure that the robot will not go too fast or too slow. We also added in a short delay so that the user has time to let go of the button before it changes again.
LEDs can be used to display how high or low the current speed is, meaning each time the speed is increased or decreased two more LEDs should be turned on or off accordingly. This will allow the user to see what speed it will be moving at. Also we will add in a beep to let us know when it changed speeds.

Final Code