Microbit Inventor Project
Normal
60 mins
225 points
What you need:
  • Computer/laptop
  • Microbit

Morse code decoder

In this lesson we will turn our Microbit into a Morse code decoder. We will enter the dots and dashes into the Microbit and it will then tell us what letter it is.

1 - What is Morse Code?

Morse code is a method used in communication to encode text characters as sequences of two different signal lengths, called dots and dashes or dits and dahs. Morse code is named after Samuel Morse, an inventor of the telegraph.

In an emergency, Morse code can be generated by improvised methods such as turning a light on and off, tapping on an object or sounding a horn or whistle, making it one of the simplest and most versatile methods of telecommunication. The most common distress signal is SOS – three dots, three dashes, and three dots.


2 - Open the starter project

We've created a starter project that has 2 lists (also called arrays) already added.

The first list is called 'alphabet' and has all the letters on the alphabet in it. The second list is called 'morse codes' and has the dots and dashes for each letter.

Open this starter project by clicking on the following link and then click the 'Edit Code' button.

https://makecode.microbit.org/_bHVCaDbwkR7b

3 - What are the lists?

Once you've opened the starter project, you'll notice that there are 2 lists created and we've already added some items to the lists.

What is a list?
A list (also called an array) is a tool that can be used to store multiple pieces of information at once. It can also be defined as a variable containing multiple other variables. A list consists of a numbers paired with items. Each item can be retrieved by its paired number.

Alphabet List
We've added all the letters in the alphabet to the "alphabet" list/array.

Morse Code List
We've also added what the Morse code for each letter is to the "morse codes" list/array. We've added these in the order of the alphabet, for example the first item in the "Morse codes" list is for 'a', the second item for 'b', the third for 'c' and so on.

4 - Create a variable called 'message'

In this project we are going to use the A and B buttons to enter a Morse code message (a series of dots and dashes) for a letter of the alphabet. The Microbit will then decode what letter it is and then display the letter using the LEDs on the Microbit.

We will need a variable to store the Morse code message that we enter, so create a variable called 'message'.

5 - Program the A button

We're going to program the A button to add a dot (the full stop character on your keyboard '.') to the message the Microbit needs to decode.

Add the following code, this will add a dot to the end of the message variable each time you press the A button.

input.onButtonPressed(Button.A, function () {
    message = "" + message + "."
})


Join our club 😃

To view the remaining 12 steps and access hundreds of other coding projects please login or create an account.

Copyright Notice
This lesson is copyright of Coding Ireland. Unauthorised use, copying or distribution is not allowed.
🍪 Our website uses cookies to make your browsing experience better. By using our website you agree to our use of cookies. Learn more