Micro:bit: Scaring Away the Ghost

The effect is achieved by sound (blowing – which is essentially a sound condition, as blowing will also produce loudness) causing the initially displayed ghost image to gradually dissipate, just like you scared away the ghost.Micro:bit: Scaring Away the GhostThis program involves several modules: basics, LED, loops, logic, variables, and mathematics. It can be considered a relatively complex small program, especially since it involves scalars, which need to be understood carefully. You can refer to “Variables in Micro:bit” and “Understanding Variables“.Micro:bit: Scaring Away the GhostLet’s focus on the following modules:

  • Loop Module: The most intuitive understanding is that it executes repeatedly (the action module that is wrapped). For example: brushing up and down once represents one cycle, so if you brush three times, it represents three cycles of up and down brushing.
  • Logic Module: Determines whether a certain event has occurred. For example, in this case, whether the loudness of the sound exceeds 128 decibels. Only when the event occurs as expected will the wrapped action module be executed.

Note: The LED lights are defined by two coordinates. For example, the coordinate of the first LED in the top left corner is (0,0), and the coordinate of the LED in the bottom right corner is (4,4). As shown in the figure below (x is represented by col in the program, and y is represented by raw):Micro:bit: Scaring Away the GhostThe basic operating logic is shown in the figure below:Micro:bit: Scaring Away the GhostMoving to the right: is accomplished by first turning off the original LED, then turning on the LED to its right. These two steps complete the operation.Micro:bit: Scaring Away the GhostYou will find that by moving one position to the right, the final result is that all the lights will eventually be randomly moved out of the display area. The effect gives the impression that the ghost is slowly dissipating.The final effect is shown in the video below:

Leave a Comment