Sign in to mBlock 5
We can use "User Cloud Message" to control Halocode remotely. We need to sign in to mBlock 5 first.
Toggle on Upload mode
Connect to the internet
1. Drag an Events block when Halocode starts up and a Wi-Fi block connect to Wi-Fi () password (). Input the Wi-Fi name and password.
2. We want to know when the Wi-Fi is successfully connected. Add a Control block wait (), a Wi-Fi block Wi-Fi is connected?, and a Lighting block all LEDs light up ().
Add a sprite
3. Under "Sprites", click "+". From the pop-up Sprite Library window, choose "Balloon1" from the Props category.
4. Right click "Balloon1" to make a duplicate. Change the costume to "c", namely color purple.
5. Delete default sprite "Panda".
Program the sprite
6. Click "+" in the Blocks area to add "User Cloud Message".
7. Program the blue balloon. Add an Events block when this sprite clicked and a User Cloud Message block send user cloud message (). Name the message "blue".
Add some special effects to the balloon
8. When the balloon is clicked, we want it to appear like being clicked. When clicked, the balloon gets brighter and bigger, and goes back to original color and size in 0.3 second. Add the following blocks: change size by (), change (color) effect by (), wait () seconds, set size to (100)%, set (color) effect to (0).
9. Likewise, we can program the purple balloon. Add an Events block when this sprite clicked and a User Cloud Message block send user cloud message (). Name the message "purple". Apply the same special effects.
Halocode receives user cloud message
10. Under "Devices", select "Halocode".
11. Add a Wi-Fi block when receiving user cloud message () and input message "blue".
Set Halocode's LEDs
12. Add a Lighting block all LEDs light up (), change the color to blue. Add a Control block wait () seconds and another Lighting block light off all LEDs.
13. Likewise, for receiving the "purple" message, duplicate the script, and change LED color to purple.
Programming result
14. Upload the program to Halocode. Disconnect Halocode from the PC, and use a battery box to power Halocode. Click the balloons on stage, and check the LEDs of Halocode.
Comments
Please sign in to leave a comment.