With built-in Wi-Fi and User Cloud Message, Halocode can play its role in your smart home. Let's build a house. On the one hand, Halocode can be the light source of the room; on the other, by connecting to a servo, Halocode can control garage door.
Set stage background
1. Delete default sprite Panda
2. Under "Background", click "Costumes", and then add "Bedroom2"
Add a button
3. Click "+" under "Sprites", and then add "Empty button1".
4. Choose "Empty button1". Then click "Costume". Add text "Bright" to the button.
Program the button
5. Under "Sprites", click "+" in the Blocks area to add User Cloud Message blocks.
6. Add an Events blockand a User Cloud Message block . Name the message "bright".
7. Add some special effects to the button when it is clicked. Drag two Looks blockand . Then add a Control block , and set the value to 0.1.
8. Add another two Looks blocksand .
Add buttons: "Soft", "Night", and "Colorful"
9. Duplicate "Empty button1" to make create another button for soft light, and edit the program accordingly. Likewise, we can create two more buttons for "night" and "colorful".
Add garage button
10. Under "Sprites", click "+" to add "Blue button45". Add text "garage lock" to the button.
11. Choose "Blue button45", and then click "Costumes". Duplicate the costume. Edit the costume. Name the two costumes "lock", and "unlock"
Program garage button
12. Choose Variables blocks, and click "Make a Variable". Name the variable "lock state".
13. Add an Events block, a control block , an Operators block , and a Variables block . Input "unlocked" to the second slot of the Operators block
14. When the door is open, we want to close the door. Add a User Cloud Message block, and name the message "lock garage". Add a Variables block and a Looks block .
15. Duplicate the script, to open garage lock. Change the variables accordingly.
16. Add some special effects to the button when it is clicked. Add the following blocks:, , , , and .
Connect to the internet
17. To use User Cloud Message, we have to connect Halocode to the internet. Add two blocks:, and .
18. Add some special effects to Halocode when successfully connected to the internet
Add light effect
19. Add a Wi-Fi block, and input "bright". Add a Lighting block , to light up all LEDs white.
20. Likewise, for User Cloud Message "soft", all LEDs will light up 40% white.
21. For User Cloud Message "night", fewer LEDs will light up. Add a Wi-Fi blockand a Lighting block .
22. For User Cloud Message "colorful". the LED right will light up with multiple colors. We'll need these blocks:, , , and .
Connect second Halocode to the servo
23. The red line of the servo means the positive pole, and is connected to the red line of the alligator clip, which is connected to the 3.3v pin of Halocode. The black line of the servo means the negative pole, and is connected to the blue line of the alligator clip, which is connected to the GND pin of Halocode. The white line of the servo is the communication line, and is connected to the yellow line of the alligator clip, which can be connected to any touchpad of Halocode. We'll use touchpad0 in this example.
Program the servo
24. Add a Wi-Fi block servo pin () rotates to () (actual rotating degree depends on the angle of the servo), to close the door., and input message "lock garage". Add a Pins block
24. Add another Wi-Fi block servo pin () rotates to () (actual rotating degree depends on the angle of the servo), to open the door., and input message "unlock grage". Add a Pins block
26. Upload program.