Case 04：Recharge the Magic Wand
4. Case 04：Recharge the Magic Wand#
To create a magic wand that can be rechargeable with the magic power.
Xiao En has successfully cheered his team up, but the long battle with the insects and the calling-together of his partners have used up the power of the magic wand, now his wand lights on with a red light. They realize that they have forgotten to recharge the magic wand, thus, they decide to recharge the magic wand.
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.
Initialize the RainbowLED strips to connect to P8 with 8 beads and set the variable to -1 in the on start brick.
Drag the if…else… brick into the forever brick to judge the status of the button connecting to P2, while the button being pressed, it circulates to execute the command: “i” = “i” +1, and set the pixel “i” as blue, refresh to show the strip and pause for 500ms; while the button not being pressed, judge if “i”< 7 and set it as -1, then set the strip of the color as red.
After powering on the strip lights up in red, while pressing the button, it starts recharging power and the strip lights on one by one in blue. If you stop pressing the button before all of the beads on the strip turn to blue, it means you fail to recharge it.