Start by creating a new project. Navigate to MakeCode for Microbit and click on 'New Project'. Give your project a name, such as 'Weather Station'.
First, we need to declare and initialize our two main variables: 'mode' and 'reading'. 'Mode' will help us determine which sensor's data we want to display, and 'reading' will store the sensor data. Add the following code:
let reading = 0 let mode = 0 mode = 1
The following are the different modes we will have:
Let's start by configuring Button A. When this button is pressed, we want 'mode' to be 1. Add the following code:
input.onButtonPressed(Button.A, function () { mode = 1 })
Next, let's configure Button B. When this button is pressed, we want 'mode' to be 2. Add the following code:
input.onButtonPressed(Button.B, function () { mode = 2 })
Now, let's configure the combination of Buttons A and B. When both these buttons are pressed, we want 'mode' to be 3. Add the following code:
input.onButtonPressed(Button.AB, function () { mode = 3 })