micro:bit - Events
Events
All programs need a beginning.
Events trigger a stack of instructions (the code inside them).
- The "On Start" event will start as soon as the micro:bit is switched on (or reset).
- The "Forever" event will start as soon as any other event has finished. If there are no other events it will start as soon as the micro:bit is switched on (or reset).
- The "On button 'A' pressed" event will start when the A button is pressed. You can change the button to 'B' or when 'A + B' are pressed at the same time.
- The "On 'shake'" event will start when the micro:bit is shaken. This will make use of the Accelerometer!
This example shows how the micro:bit can have multiple events.
When the program starts it displays the text string "Hello World!".
It then shows a smiley face forever.
When the A button is pressed it displays the letter 'A'.
When the B button is pressed it displays the letter 'B'.
When the micro:bit is shaken it shows a sick face!
The purple input events will interrupt the 'forever' event, but not the 'on start' event.
Challenges
- Write a simple program that will show a message when you press the A button.
- Write a simple program that will show a different message when you shake the micro:bit.
Key Words
Event
An action that can trigger stack of code in a computer program. Events could happen at any time.
Input
Data that is entered into a computer system, this can be manually or by using sensors.
Accelerometer
A sensor that detects changes in acceleration. It is used to detect movement. You will find accelerometers in smartphones and game controllers (like the controllers for the Nintendo Switch).