Microbit Analogue Inputs
In the previous topic we looked at digital inputs ( any inputs that have have only 2 states on/off – buttons / shake input). In this topic we have look at analogue inputs – any inputs /sensors that can have a range of values.
The Microbit has a number of in-built analogue sensors, such as:
- Temperature sensor
- Light sensor
- Tilt sensor
Different sensors return different value ranges.
Compass Bearing Sensor
- The compass bearing sensor detects which direction the Microbit is facing and returns the angle in degrees.
- Returns a value between 0 and 360
- The temperature sensor detects what the current temperature is in degrees Centigrade.
- Return an integer (whole number)
- Detects the tilt angle for the microbit on either the X axis(left / right) or Y Axis (forward/backwards)
- Return a positive or negative integer (whole number)
Light Level Sensor
- The light level sensor detects how much light the Microbit is being exposed to
- Returns a positive integer between 0 and 255.
Challenge 1 – What’s the temperature?
Create a script that every time you press the A button, it tells you the temperature.
- The program displays the temperature
- The program says ‘The temperature is 30 C”
- If the temperature is greater than 30 degrees it then displays a sunny symbol
- If the temperature is less than 20 degrees it displays a snowman.
Challenge 2 – Tilting Microbit
When the A+B buttons are press the microbit should:
- display the left/right tilt.
- wait 2 seconds
- Display the forward/backward tilt
The microbit should finally say
‘I’m tilting Forward & Right’ (or whatever way it is tilting)
Get the Microbit to display a dot on the screen that indicates which direction the Microbit is tilting left / right / forward / back.
Gold Hint blocks
Challenge 3 – Microbit Compass
Get the Microbit to say the bearing.
If the Microbit is facing exactly north / east / south / west it should display N E S W instead.
The Microbit should always display a letter bearing, even if the bearing is not exact. E.g. if the bearing
The code below will probably help you out!
Challenge 4 – Microlight!
Whenever you shake the microbit:
Get your program to tell you the light level
If the light level is below half, your program should turn on all the LEDs for 10 seconds.
Your program should keep repeating the above code until the B button is pressed and then the microbit shut stop checking the light level.