The User Cloud Message extension enables data to be shared across devices and projects. To use this extension, you need to sign in to mBlock 5.
Let's use CyberPi as an example to understand the User Cloud Message extension.
1. Sign in to mBlock 5
Click the Log in/Sign up icon on the right of the toolbar.
2. Create a new project
Choose File > New on the toolbar.
3. Add CyberPi
Note: If you have set CyberPi as your most frequently used device, CyberPi is automatically added when you create a new project, and you can skip this step. If you haven't, follow the steps to add CyberPi.
(1) Click the Devices tab, delete the added device, and click + add to add CyberPi.
(2) Use a USB cable (Type-C) to connect CyberPi to your PC and click Connect to connect CyberPi.
(3) Set the programming mode to Upload.
4. Start programming
With mBlock 5, you can program a sprite to control CyberPi remotely.
4.1 Add the User Cloud Message extension
(1) Click the Sprites tab and click + extension at the bottom of the Blocks area.
(2) On the Extension center page that appears, click + Add at the bottom of User cloud message.
After being added, the extension and its blocks are displayed in the Blocks area.
4.2 Program the sprite "Empty button1"
(1) Click × to delete the default sprite Panda on the Sprites tab.
(2) Click + add on the Sprites tab. In the Sprite Library dialog box that appears, search for button, choose Empty button1, and click OK.
(3) Choose Empty button1 on the Sprites tab and drag the Events block when this sprite clicked to the Scripts area.
(4) Drag the User cloud message block send user cloud message ( ) to the Scripts area and name the message light_on.
(5) Add some effects on Empty button1 to make it look like being clicked. Drag the Motion block change y by ( ) to the Scripts area and enter -2, and then drag the Looks block set color effect to ( ) to the Scripts area and enter -10.
(6) Drag the Control block wait ( ) seconds to the Scripts area and enter 0.2; drag the Motion block change y by ( ) to the Scripts area and enter 2; and drag the Looks block set color effect to ( ) to the Scripts area and enter 0.
4.3 Program CyberPi
Now, let's program CyberPi. Ensure that the name of the message to be received by CyberPi is the same as that sent by Empty button1.
4.3.1 Connect to the network
(1) Drag the Events block when CyberPi starts up to the Scripts area.
(2) Drag the IoT block connect to Wi-Fi ( ) password ( ) to the Scripts area and enter SSID and password of an available wireless network.
(3) To ensure network connection, drag the Control block wait until ( ) to the Scripts area, and then drag the IoT block network connected? to the Scripts area.
(4) Drag the LED block display ( ) to the Scripts area and set the colors of all the LEDs to green to indicate that the network is connected.
4.3.2 Write the User Cloud Message program
When CyberPi receives the user cloud message "light_on", make all LEDs on it lit up in red and then go off.
(1) Drag the IoT block when receiving user cloud broadcast ( ) to the Scripts area and enter the name light_on.
(2) Drag the LED block display ( ) to the Scripts area and set the colors of all the LEDs to red.
(3) Drag the Control block wait ( ) seconds to the Scripts area, and then drag the LED block turn off LED ( ) to the Scripts area.
(4) Click Upload to upload the program to CyberPi.
(5) Restart CyberPi, wait until all the LEDs on it are lit up in green, click Empty button1 on the stage, and see what happens.
(6) Disconnect CyberPi from mBlock 5, click Empty button1 on the stage, and see what happens.
4.4 Save the project
Click Save on the toolbar to save the project to My Projects.
After the project is saved, you can sign in to the same mBlock 5 account on other devices to open the project from My Projects.
Restart CyberPi, wait until all the LEDs on it are lit up in green, click Empty button1 on the stage, and see what happens.
You can use the sprites on mBlock 5 to control Halocode and Codey remotely in a similar way.