3. Case 03: Coping with Stress
To create a magic wand to show a smile face.
Xiao En sends out the flying saucer and gets together with his partners, they feel depressed for their first war with the insects enemy. Xiao En finds out a way to rebuild their confidence and face the problems positively.
Click “Advanced” in the MakeCode drawer to see more choices.
We need to add a package for programming, . Click “Extensions” in the bottom of the drawer and search with “magicwand” in the dialogue box to download it. (Kindly note this package is still in the verifying process and pls search with “https://github.com/elecfreaks/pxt-magicwand “ before it’s ready)
Note: If you met a tip indicating that the codebase will be deleted due to incompatibility, you may continue as the tips say or build a new project in the menu.
Choose the variables in the MakeCode drawer and write the letter “i” in the dialogue box to confirm it.
Drag the variable brick and set it as 0 into the on start brick.
Drag the if…else… brick into the forever brick to judge the value of the variable and the status of the button connecting to P2. While “1”=1 and the button connecting to P2 is pressed, it shows a smile face, then set to pause for 500ms and show an icon, at last set the variable as 0.
Drag the while vibrating brick and set it as 6g, choose the show number brick to show the variable “i” and set it to 1.
While shaking the magic wand, it suggests the consuming status of the magic power, then press the button to show a smile face.