Microbit2

From Interaction Station Wiki
Jump to navigation Jump to search

If Statement

Why is the temperature so complicated?

What is happening?

Temperature is a number. To get something done we need to tell the microcontroller some "program", like:

do something if the temperature gets below 10 degrees.

This "if" is one of the most important programming principles.

If something is true do THIS. if that something is NOT true, do THAT.

In fact the button input is also like an IF statement:

if the button is pushed, then.....

So we need an IF: - from "LOGIC"

Mb30.png

Then we need a comparison from LOGIC

Mb31.png

Then we need temperature form INPUT

Mb32.png

We need to puzzle this inside each other, the shapes are helping:

Mb33.png

and we get this - inside the "FOREVER"

Mb26.png

Let's take a look at the Javascript:

Mb34.png



Comparison (If you want to know)

Also with the Arduino we use an "IF-statement"

The Arduino doesn't know what is connected to it. For temperature this could be an NTC. (Many other ways to measure the temperature.) The NTC produces an "analog" number, when rightly connected. With special code, adapted to this NTC we have to transform this number in what is called degrees Celsius.

This NTC and the code can be found on this WIKI: http://interactionstation.wdka.hro.nl/wiki/Thermistor

Thermistor01.png

We can see the code:

Mb35.png

And we discover the IF statement:

Mb36.png