7. case 05 Remote Control¶
7.1. Our Goal¶
Use another micro:bit control our motor:bit car.
1 x motor:bit smart car kit
1 x micro:bit
7.3. Background Knowledge¶
What is radio?¶
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.
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.
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.
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
Create a loop to check the value of
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.
Code of Remote Controller¶
Link of the whole program: https://makecode.microbit.org/_fDtH2ze0X5Wc
You can also download the program from the page below.
Once powered on, the car moves forward at the speed of 80. Press button A on the remote controller, the car turns left. Press button B, the car turns right.