Skip main navigation

Challenge 3: Create a new output

Challenge 3: Create a new output

From the previous challenges, you’ve learnt how to deal with input from the user, connect a speaker to the micro:bit, deal with input from a sensor, edit that data and display data on the micro:bit screen.

We’re onto intermediate challenges now. The micro:bit screen is useful but it’s also very small. What if we wanted to display our information to people from a distance? Or if we wanted to display a lot of information at once. We’re going to add another output to the micro:bit to use as a display.

For this challenge we’re going to display data from the real world in lights. We’re going to take the temperature of the room and display it as different coloured lights.

In the next step I’ll show you how to add a new library to the micro:bit to control multi-coloured lights.

Libraries

Libraries are very common in coding. A library contains code that someone else has written for a specific reason. There are libraries for dealing with dates in code, libraries for creating graphs and libraries to control hardware. In this case, we want to add a library to control hardware. We don’t have to know exactly how the hardware works, the library will do that work for us. It gives us simple to use code to control the hardware.

Hardware

This is the hardware we’re going to use:

  • A strip of eight lights
  • three crocodile/alligator clips

The strip contains eight red, green and blue lights. Each light can be controlled individually or the entire strip can be controlled. The lights can change to any colour combination of red, green and blue.

Hardware neededHardware needed
(Click to expand)

Plan

We have 8 lights. I’m going to create 4 zones of temperature. Two lights will represent each zone. If it’s cold out, I want the lights at the bottom of the strip to turn on blue. If it’s warm out, I want all the lights to turn on.

Our plan is quite complicated, so let’s draw it out in more detail.

When the temperature is greater than 0 degrees, lights 0 and 1 will be blue

When the temperature is greater or equal to 5 degrees, lights 2 and 3 will be orange

When the temperature is greater or equal to 10 degrees, lights 4 and 5 will be green

When the temperature is greater or equal to 15 degrees, lights 6 and 7 will be red

Let’s take 7 degrees as an example. If it’s 7 degrees, what lights will come on?

Answer: Lights 0, 1, 2 and 3 will be on. 0 and 1 will be blue. 2 and 3 will be orange.

When it’s over 15 degrees, all of the lights will be on and coloured.

With such complicated code, I would write this in a text based language like JavaScript or Python.

This article is from the free online

Build a Physical Computing Prototype

Created by
FutureLearn - Learning For Life

Our purpose is to transform access to education.

We offer a diverse selection of courses from leading universities and cultural institutions from around the world. These are delivered one step at a time, and are accessible on mobile, tablet and desktop, so you can fit learning around your life.

We believe learning should be an enjoyable, social experience, so our courses offer the opportunity to discuss what you’re learning with others as you go, helping you make fresh discoveries and form new ideas.
You can unlock new opportunities with unlimited access to hundreds of online short courses for a year by subscribing to our Unlimited package. Build your knowledge with top universities and organisations.

Learn more about how FutureLearn is transforming access to education