Step 1: Make it
What is it?
Use a simple function to convert centigrade readings from the micro:bit's temperature sensor to Fahrenheit.
How it works
- The micro:bit's processor has a built-in temperature sensor input which gives readings in centigrade.
 - Using functions allows you easily to convert the temperature to Fahrenheit.
 - The convertCtoF function means you can re-use the conversion code easily, for example in a maximum-minimum thermometer.
 - The function is called by using convertCtoF in place of a variable or number when you press button B on your micro:bit.
 - We pass to the function the temperature in centigrade.
 - The function then takes the number passed to it, stored in a variable called C, and converts it to Fahrenheit by multiplying it by 1.8 and adding 32.
 - The function then returns the converted number so when you press button B the temperature is shown in Fahrenheit on the LED display output.
 - If you press button A, the temperature is shown in centigrade.
 
What you need
- micro:bit (or MakeCode simulator)
 - MakeCode or Python editor
 - battery pack (optional)
 
Step 2: Code it
Step 3: Improve it
- Improve the display by showing 'C' or 'F' after the temperature in centigrade or Fahrenheit.
 - Create your own function to add a conversion to degrees Kelvin when you press buttons A and B together.
 - Add Fahrenheit conversions to a maximum-minimum thermometer or an indoor outdoor thermometer.
 
This content is published under a Creative Commons Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) licence.


