Scratch
Advanced
60 mins
170 points
What you need:

Morse Code

Morse Code is probably the most famous way of sending "encoded" messages. In this project we program a robot to tell us what the morse code for each letter in the alphabet 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 a robot sprite and 2 lists already added. Open this starter project by clicking on the following link:

https://scratch.mit.edu/projects/455087138/editor/

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 in Scratch?
A list (also called an array in other programming languages) 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.

Morse Code List
We've also added what the morse code for each letter is to the "morse codes" list. 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 - Ask what to encode

Let's get coding! We're going to activate the robot by clicking on it, once we do the robot will ask us what letter we want to translate to morse code.

Add the following code to the Retro Robot sprite.

when this sprite clicked ask [what letter do you want to encode?] and wait

The ask   and wait block is a Sensing block. The block will make the sprite using the block say the question and show an input box at the bottom of the screen.

Whatever you type in the box will be saved into the answer block. 

5 - Create a custom block called 'encode'

Create a custom block called 'encode' and add an input called 'letter' to it. We will use this custom block to translate the letter to it's corresponding morse code.

Once you've created it you will notice there's a encode   block in the toolbox and a define [ encode (letter) ] block in the code area.

Add the encode   block underneath the ask   and wait block and put the answer block inside it.

when this sprite clicked ask [what letter do you want to encode?] and wait encode (answer) define encode (letter)



Join our club 😃

To view the remaining 8 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.

Scratch is developed by the Lifelong Kindergarten Group at the MIT Media Lab. It is available for free at https://scratch.mit.edu
🍪 Our website uses cookies to make your browsing experience better. By using our website you agree to our use of cookies. Learn more