A - Events
blocks, events and messages

In this section, we are learning different ways for the micro:bit to receive commands, or as they are called in coding, events. Events enable the interaction between us and the device (micro:bit). Some equivalent events in our daily life are:
Pressing a key on your keyboard
Starting a car by turning a key or pressing a button
Saying a command to enable your phone's digital assistant
The events we are exploring in the micro:bit are on start, forever, on shake and on button A pressed.β
Create a new project and clear the Workspaceβ
Create a new project by going to makecode.microbit.org and deleting the current blocks (on start and forever) from the Workspace by dragging them to the Block groups area.

βEvents blocks
We will code our micro:bit to display the word "Hi", using different events. Go over the process and try to spot the differences and when would you choose one over the other
on start, forever, on shake and button A pressed
on start runs the code inside it as soon as the micro:bit is powered. A very useful place to set up your application.
forever executes the code inside it as long as the micro:bit is powered. Forever, as long as the micro:bit is running.
shake is lots of fun since it executes the code inside it when the user shakes the micro:bit. This is possible as the micro:bit can detect acceleration.
on button A pressed works just like your tv remote or the buttons on a game console. The device detects a button being pressed and runs the code inside it.
Did you notice that the blocks in the Block groups area are colour-coded? This makes it easy to look for blocks you see in the example activities.
We can trigger events with many different blocks in MakeCode as we saw in this section, but so far we only displayed text. In the next section, B - Animations, we are working with images.
Last updated
Was this helpful?