edit

# case 05 Remote Control

## Our Goal¶

• Use another micro:bit control our motor:bit car.

## Background Knowledge¶

• Radio is the technology of using radio waves to carry information, such as sound, by systematically modulating properties of electromagnetic energy waves transmitted through space, such as their amplitude, frequency, phase, or pulse width. When radio waves strike an electrical conductor, the oscillating fields induce an alternating current in the conductor. The information in the waves can be extracted and transformed back into its original form.

## Software¶

Microsoft MakeCode

## Programming¶

### Step 1¶

Click Advanced in the code drawer of MakeCode to see more options.

To program for motor:bit, we have to add a package. Find Add Package in the bottom of code drawer and click it. This will pop up a dialogue box. Search for "motorbit" and then click to download this package.

Note: If you get a hint that some packages will be deleted due to the problem of incompatibility, you can either follow the prompts, or create a new project in the project menu.

### Step 2¶

• Let's start by coding our remote controller (i.e. our transmitter).
• At the beginning, set radio group to 88.(Same group with the receiver.)
• Press button A, radio send number 1.
• Press button B, radio send number 2.

### Step 3¶

• Now, let's write the receiver program for our motor:bit car.
• When start, set radio group to 88. (Same group with the transmitter.)
• Make the car move forward by a default speed of 80.
• When radio signal is received, assign the received number to variable `item`.
• Create a loop to check the value of `item`.
• If it is 1, the car will turn left at the speed of 80 and delay time for 0.5s.
• If it is 2, the car will turn right at the speed of 80 and delay time for 0.5s.
• If not both of them, the car just move forward at the speed of 80.

## Program¶

#### Code of Remote Controller¶

Link of the whole program: https://makecode.microbit.org/_fDtH2ze0X5Wc