Example Code for micro:bit-Remote Control Handle
Use the GamePad for microbit (V2.0) as a wireless remote control to control the movement of the mobile platform. Press different buttons to send different numbers to control the mobile platform to perform different actions, and release the buttons to stop the mobile platform.
Hardware Preparation
- [DFR0536]GamePad for microbit (V2.0) ×1
- micro:bit ×2 (one for GamePad, one for mobile platform)
- Mobile platform ×1
Software Preparation
- MakeCode programming platform address: https://makecode.microbit.org
- GamePad library: https://github.com/DFRobot/pxt-gamePad (install via Advanced > Add package)
Wiring Diagram
Plug one micro:bit into the GamePad for microbit (V2.0), and plug the other micro:bit into the mobile platform.
Other Preparation Work
Set both micro:bit to the 1th wireless group.
Sample Code
Graphical source program of handle: Gamepad
Graphical source program of car: Mobile Platform
Result
-
Handle program execution result:
- Set the wireless to group 1.
- When different buttons are pressed, send different numbers to let the car performs different actions.
- When the button is released, the number 0 is sent to make the car stop.
-
Mobile platform program execution result:
- Set the wireless to group 1.
- When receiving different numbers, let the car perform different actions such as forward, backward, turn left, turn right.
Was this article helpful?
