📊 micro:bit Data and Climate Change
  • Introduction
  • Data
  • Climate Change
  • Our Tools
    • 01- micro:bit
    • 02 - MakeCode
      • A - Events
      • B - Animations
      • C - Counting
      • D - If Hot
    • 03 - Servo Motor
      • Coding your first servo motor on MakeCode
    • 04 - Neopixel
      • Coding your first neopixel on MakeCode
  • Activities
    • Tools and Data Together
      • 01 - micro:bit and Data
      • 02 - Servo Motor and Data
      • 03 - Neopixel and Data
  • Showcase Projects
    • 01 - Air Pollution
      • A - Servo Motor
      • B - Neopixel Grid
    • 02 - Green Energy Forecast
    • 03 - Temperature Change
      • A - Neopixel Grid
      • B - Neopixel Ring
    • 04 - Heavy Precipitation Days
      • A - Neopixel Grid
      • B -Servo Motor
      • C-Neopixel Fairy Lights
    • 05 - Greenhouse Gas Emission
      • A - Neopixel Grid
      • B - Neopixel Fairy Lights
  • 🚀Extra Missions
  • Support Material
    • Data on the Run
    • Data Visualization Examples
    • Data Science of Climate Change by Lucie Luneau
    • Ideas from the Canadian Space Agency - CSA
    • CASC + Science Spotlight
Powered by GitBook
On this page

Was this helpful?

Export as PDF
  1. Our Tools
  2. 02 - MakeCode

A - Events

blocks, events and messages

Previous02 - MakeCodeNextB - Animations

Last updated 2 years ago

Was this helpful?

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​
​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.

Create a new project by going to and deleting the current blocks (on start and forever) from the Workspace by dragging them to the Block groups area.

makecode.microbit.org