πŸ“Š 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

D - If Hot

PreviousC - CountingNext03 - Servo Motor

Last updated 2 years ago

Was this helpful?

​ ​

In this section, we are taking our code to a new level. As humans, we see, smell, touch, taste and hear the world around us, and we are going to use some of those senses to help the micro:bit do something similar, by utilizing different sensors built into it.

The first sensor we'll work with is the ability that the micro:bit has to detect temperature and along with it, we'll learn the concept of if statements in coding.

If statements provide computers with the ability to choose between different options or paths. It opens many different possibilities and makes our programs more interesting and diverse.

We don't need a physical micro:bit to test the temperature option. The emulator provides a way for us to see and test different temperature levels.

​Temperature

Getting a temperature reading from the micro:bit is very simple. We use the provided block temperature (C), wrapped by the show number block.

Don't forget to test your progress using the micro:bit emulator, or a micro:bit, if you have one available.

​If Statements - Conditionals

If-else statements are used to control what the code will execute when a particular condition is fulfilled. In a way, they provide options for our code to make choices.

  • Add the if block to our existing code

  • Add the comparison block located in the Logic section

  • Complete the if block by:

    • Adding the temperature block

    • Change the < (less than) sign in the middle to be > (greater than)

    • Add a number that would indicate a hot temperature

By now you know the routine: test the application in the emulator or on an actual micro:bit if you have one available!

These projects ​​​will help you when working on the main Activities as they all use micro:bits and MakeCode as the brains controlling the visualizations and servo motors. It is time to continue, learning about the other tools. See you in the next section 03 - Servo Motor.

🍎Teacher's Corner - If statements
  • The if statement executes a statement if a specified condition is truthy. If the condition is falsy, another statement can be executed..

More about from MakeCode

β€‹β€‹β€‹πŸŽTeacher's Corner - Logic operators

For more information about the provided blocks regarding logical operators visit:

  • Greater than

  • Equality

  • AND

  • OR

  • Not

Some more information from MakeCode

  • logic

  • compare

Teacher's Corner - Battery pack

his and many other applications created for the micro:bit can be better explored using a battery pack. It is not necessary but gives mobility to the micro:bit.

micro:bit battery pack

🍎
info
MDN
if statements
link
link
link
link
link
link
link