The LEDs

Sequencing

The order in which actions take place is very important when creating an algorithm. When making a cup of tea, you don't pour the water into the cup until after it has boiled!

Imagine you were out for a walk on the beach one evening and you saw a light flashing out at sea...

What does it mean?

Look at the flashing light.

Can you identify the pattern?

The sequence of the lights is very important. The light is flashing SOS - an emergency signal.

How long is the light on for each time?

How long is the light off each time?

LEDs

As well as using the basic output blocks that display text, numbers and images, it is possible to individually turn LEDs on and off.

To do this we need to understand that each LED has a location based on grid-references. However unlike grid references we may have used in Maths or Geography, the axes start at the top-left not the bottom-left.



Pauses?

Unlike the basic output blocks, the LED blocks do not have any built in pauses, so will appear to instantly turn the chosen LED on or off.

This means that if we wish to flash an LED and be able to see it, we need to add a pause.

Compare the two scripts below.

Press A or B too see the code working.

When you press button A, the LED at coordinates (0,0) will turn on and off so fast, you won't see the LED flash.

When you press button B, the LED at coordinates (0,0) will turn on, pause for 1 second and then turn off.

How do I flash an LED more than once?

To Flash an LED more than once we will need to turn it on and off, then pause, and do it again.

Press A to see the LED flash once.

Press B to see the LED flash twice.

Watch the video below to see how to flash a single LED

microbit - leds.mp4

Challenges

SOS

Create a program that will flash SOS in morse code using the LED at (0,0).

The LED should:

  • give 3 short flashes

  • followed by 3 long flashes

  • followed by 3 short flashes.

A short blink lasts 500 milliseconds and a long blink lasts 1000 milliseconds.
Put a pause of 500 ms between each flash.

Key Words

Axes

Reference lines used to locate items (in our case LEDs) on a grid. The micro:bit has two Axes:

    • The X-axis which runs horizontally left to right

    • The Y-axis which runs vertically top to bottom

Sequence

The particular order that actions take place, one following the other.

Algorithm

A set of instruction that can be followed in order to complete a task

Program

A stored set of instructions for a computer to follow that completes a task.