Reading the micro:bit temperature with input.temperature()

Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.

Reading the micro:bit temperature with input.temperature()

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Which code reads the micro:bit's temperature?
A input.temperature()
B input.temp()
2. What unit does input.temperature() give you?
A Degrees Celsius
B Degrees Fahrenheit
3. Which line shows the temperature on the LED screen?
A basic.showString(input.temperature)
B basic.showNumber(input.temperature())
4. Which line stores the temperature reading in a variable?
A let temp = input.temperature()
B let temp = "input.temperature()"
5. True or false: input.temperature() returns a number.
A False, it returns a word like "warm"
B True, it returns a number like 22

Match the Pairs

Draw a line connecting each item on the left to its match on the right.

Left columnRight column
1basic.showNumber(input.temperature()) AReads the temperature in degrees Celsius and scrolls the number across the micro:bit LED screen
2let temp = input.temperature() Bbasic.showNumber(input.lightLevel())
3Show the micro:bit's light sensor reading on the LED screen instead of the temperature CStores the current temperature reading in a variable called temp so it can be used again later
4Store the temperature in a variable, then display the stored value DThe brackets after input.temperature are missing, so the function is never called and no reading is returned. It should be input.temperature().
5basic.showNumber(input.temperature) EThe function name is misspelled as temprature. It must be spelled input.temperature() exactly or the code will not work.
6let temp = input.temprature() Flet temp = input.temperature() basic.showNumber(temp)

Definitions

input.temperature()

Fill in the Blanks

Complete each line of code by filling in the missing parts.

1.
basic.showNumber(input.___________())
2.
___ temp = input.temperature()
3.
let temp = input.temperature() basic.showNumber(____)
4.
let light = input.__________()
5.
basic.__________(input.temperature())

Spot the Error

Shade in the letter of the line that contains an error.

Question 1
A let temp = 0
B basic.forever(function () {
C temp = input.temperature()
D basic.showNumber(tmp)
E })
Question 2
A let temp = input.temperature()
B basic.pause(500)
C basic.showNumber(temp())
Question 3
A let t = input.temperature()
B if (t > 30) {
C basic.showString(Hot)
D }
Question 4
A let light = 0
B light = input.lightlevel()
C basic.showNumber(light)
Question 5
A let temp = input.temperature
B basic.showNumber(temp)
C basic.pause(1000)

Answer Key

Reading the micro:bit temperature with input.temperature()
Section A: Quick Questions
Q1
A — input.temperature()
Q2
A — Degrees Celsius
Q3
B — basic.showNumber(input.temperature())
Q4
A — let temp = input.temperature()
Q5
B — True, it returns a number like 22
Section B: Match the Pairs
Q1
basic.showNumber(input.temperature()) → Reads the temperature in degrees Celsius and scrolls the number across the micro:bit LED screen
Q2
let temp = input.temperature() → Stores the current temperature reading in a variable called temp so it can be used again later
Q3
Show the micro:bit's light sensor reading on the LED screen instead of the temperature → basic.showNumber(input.lightLevel())
Q4
Store the temperature in a variable, then display the stored value → let temp = input.temperature() basic.showNumber(temp)
Q5
basic.showNumber(input.temperature) → The brackets after input.temperature are missing, so the function is never called and no reading is returned. It should be input.temperature().
Q6
let temp = input.temprature() → The function name is misspelled as temprature. It must be spelled input.temperature() exactly or the code will not work.
Section C: Definitions
Q1
input.temperature() — A micro:bit block that returns the temperature reading in degrees Celsius as a number. You can show it with basic.showNumber() or store it in a variable.
Section D: Fill in the Blanks
Q1
basic.showNumber(input.temperature())
Q2
let temp = input.temperature()
Q3
let temp = input.temperature() basic.showNumber(temp)
Q4
let light = input.lightLevel()
Q5
basic.showNumber(input.temperature())
Section E: Spot the Error
Q1
D — The variable is called temp, but the broken line uses tmp, which was never created. It should be basic.showNumber(temp).
Q2
C — temp is a variable holding a number, not a function, so it has no brackets after it. It should be basic.showNumber(temp).
Q3
C — Text shown on the micro:bit must be in quotation marks. Without them, Hot looks like a variable name. It should be basic.showString("Hot").
Q4
B — Names are case-sensitive. The sensor function is input.lightLevel() with a capital L, not input.lightlevel().
Q5
A — input.temperature is a function, so it needs brackets to run and return the reading. It should be input.temperature().