MICROBITS

microbit.png

Micro-bits are small computers that allows you to program simple computer programs with several inputs.

We use micro bits along with makecode to create programs that respond to our inputs.

Try makecode here


If - Then Statements

Robotic language runs on very simple logic: action and response. This can be coded in an if-then statement, also known as a conditional statement!

Some real life action and response examples:

If you mow the lawn then i’ll give you 5 bucks

If you hit your little brother then he’ll get angry

If you close the lock the front door then the house is secure

Computers are no different, they work on the exact same principle. You can essentially code if-then statements.

If (true) ⟵ If the statement is considered ‘true’

{do this} ⟵ then execute the commands in this bracket

For example:

If (sky == raining) {

open umbrella;

}

You can even code computer if-then statements as have multiple outcomes using if-else statements

If (true) ⟵ If the statement is considered ‘true’

{do this} ⟵ then execute the commands in this bracket

else ⟵ (aka otherwise)

{do this} ⟵ then execute the commands in this bracket

For Example

If (sky == raining) {

open umbrella;

}

else {

do nothing;

}


Try it yourself

  1. Start by coding ‘Forever’ into your microbit

  2. Code an if-then statement to display “stop pressing me” when button ‘a’ is pressed three times

  3. Add an else statement to display “keep pressing me” if button ‘b’ is pressed


Challenge 1

Code your microbit to count down from 10 to 0:

It should display the numbers 10 through 0 on the microbit display

Challenge 1.1

Pressing button ‘a’ should pause the counter, the display should also pause the number being counted down on the display.

Challenge 1.2

Pressing button ‘a’ should pause the counter the display should also pause on the number being counted down, pushing button ‘a’ should continue the countdown.

Challenge 1.3

Pressing button ‘b’ should resets the counter back to 10