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-662a07c747a2f930483284-i/] method.
[crayon-662a07c747a37046541608/]

Learn More: What’s a library?

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

Any code that starts with [crayon-662a07c747a39006620196-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-662a07c747a3b513437877-i/] ,enter the following to initialize the use of the remote control within the sketch.
[crayon-662a07c747a3d875680031/]
After establishing use of the remote control, you will have to establish serial communication with the board.
[crayon-662a07c747a3e104362079/]

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-662a07c747a3f937961427-i/] to assign a time step for how fast the board should check for entries from the remote control.
[crayon-662a07c747a40001423454/]

Next, inside  [crayon-662a07c747a42305765473-i/], enter the following
[crayon-662a07c747a43870709118/]
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
[crayon-662a07c747a44220366032/]
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-662a07c747a45195121588-i/] and it will perform the desired function. The “if” statement should resemble the following
[crayon-662a07c747a46297110267/]
Next, create an “else if” statement but for “KEY_D”.
[crayon-662a07c747a47580683985/]
Lastly, assign a command for what happens when none of the above conditions are met. This is done by creating an “else” statement.
[crayon-662a07c747a48201448275/]

if, else if, and else

If statements allow for the user to create conditions, and assign actions when those conditions are met.
[crayon-662a07c747a49689908101/]
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.
[crayon-662a07c747a4a501001871/]
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.
[crayon-662a07c747a4c120875810/]
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

Activity:

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

Final Code

[crayon-662a07c747a4e569450198/]