1. Purpose of the Case
Control the CoCube robot using a WeChat mini-program.
2. Materials Used
3. Software Platform
4. Start Programming
The WeChat mini-program communicates with the CoCube robot via Bluetooth Low Energy (BLE). First, you need to load an interface program onto the CoCube robot using MicroBlocks IDE and customize it as needed. Then disconnect the MicroBlocks IDE from the CoCube robot. Finally, connect to the CoCube robot using the WeChat mini-program to achieve real-time control!
- Load Interface Program for CoCube Robot
MicroBlocks - Case 08 WeChat Mini-Program Interface
Connect CoCube Robot and MicroBlocks IDE
Customize Functional Keys
The example code is shown below:
In this code:
The "When I Receive _" hat block handles joystick messages to control the movement of the CoCube robot. No modifications are required.
The "When I Receive A," "When I Receive B," "When I Receive X," and "When I Receive Y" blocks correspond to the A, B, X, and Y buttons in the WeChat mini-program and can be customized as needed.
Disconnect CoCube Robot from MicroBlocks IDE
After debugging, remember to disconnect the CoCube robot from the MicroBlocks IDE; otherwise, the robot cannot be connected to the phone simultaneously.
5. WeChat Mini-Program
Open the WeChat Mini-Program
Open the WeChat app on your phone, scan the QR code for the WeChat mini-program, and open the "CoCube Robot" mini-program.
Connect to CoCube Robot
Click the "Search for CoCube Devices" button. If it's your first time using it, you may be prompted to enable Bluetooth permissions; click confirm.
From the list of devices, find the Bluetooth ID for your CoCube robot and click to connect.
Remote Control CoCube Robot
The virtual joystick on the left controls the movement of the CoCube robot's chassis. The size of the stick input adjusts the speed, and it supports mixed control (e.g., sliding forward-left will make the robot turn forward-left).
The A, B, X, and Y buttons on the right correspond to the custom functions defined earlier in the MicroBlocks IDE.
6. Challenge: Simulated Driving
Using the driving simulation map, test your driving skills!
Can you design a timer directly in the CoCube to track your race performance?