How to Program the Remote Control

This lesson will go over how to program the remote control found inside the Rokit Smart Kit.

First, begin the code by including the smart inventor library. Enter the following before the [crayon-666c87e1ac334470577238-i/] method.

Learn More: What’s a library?

A library is a saved set of [crayon-666c87e1ac33f597687720-i/]  and variables that provide users with improved functionality when coding.

Any code that starts with [crayon-666c87e1ac340860098813-i/]  is a function in the SmartInventor library.  Any variable that highlights ORANGE, is an initialized variable from an included library.

Learn More

Next, inside  [crayon-666c87e1ac342086098894-i/] ,enter the following to initialize the use of the remote control within the sketch.
After establishing use of the remote control, you will have to establish serial communication with the board.

Serial.begin( )

Serial.Begin( BAUD rate);

This function will establish a high transfer BAUD connection between the remote and the board. The higher the BAUD number the faster the board will process information, but may yield a high chance for errors. The lower the BAUD number the slower the board will process information, but may yield a low chance for errors.

Acceptable BAUD rates range from 300 to 250000. Make sure that the BAUD rate is a number that is found within the lower right corner of the Serial Monitor.

Next, input a [crayon-666c87e1ac346718714787-i/] to assign a time step for how fast the board should check for entries from the remote control.

Next, inside  [crayon-666c87e1ac34a753862756-i/], enter the following
This will create a global variable named “keyData” that will store the information from the remote regarding the most recent button pressed.

Next, we will go over how to create and use an “if, else if, and else statement”

This will make it so that “if” you press a particular button on the remote control, then a corresponding text will be printed. The first “if” statement will be as follows
This initializes a condition statement to check that “if” an action is met perform the action within the braces { }. In this case add a print command into the position of the [crayon-666c87e1ac34d775516295-i/] and it will perform the desired function. The “if” statement should resemble the following
Next, create an “else if” statement but for “KEY_D”.
Lastly, assign a command for what happens when none of the above conditions are met. This is done by creating an “else” statement.

if, else if, and else

If statements allow for the user to create conditions, and assign actions when those conditions are met.
Else if statements allow the user to stay within the original “if” statement and indicate alternate conditions to perform a new action based on different conditions.
Else statements will encompass all conditions not specified. This will be the go-to action for conditions other than those listed in the if and else if statements.
When creating “if” statements keep in mind that they must meet the following

  • For every if statement, there can only be one else statement
  • There can be more than one else if statement within the same if statement


Program an action for all of the available key inputs on the remote: [crayon-666c87e1ac355878267363-i/]

Final Code