Inputs & Outputs
Invent Logo

Computers can use both input and output devices. An input device sends information to a computer. An example would be a keyboard or a mouse. An output device receives information from a computer. An example is a computer monitor or speakers.

We've already used one output device. The drive module is a good example. The two motors are controlled by a signal from the robot so they are output devices. Let's now use some more outputs. We'll use the in-built LEDs.

Inputs & Outputs
The LEDs

We've already looked at some of the other LEDs that show the status of the robot, but there are two additional LEDs that you can control at the front of the robot; one on the left and one on the right.

The LEDs
Testing them out

Start a new program and drag the 'LED' block into your code. This block allows you to select either the left or right LED and specify the colour you want. You can select any colour for either LED.

Try this out now. Set one of your LEDs to green and the other to red.

Testing them out
Morse code

Morse code was invented by Samuel Morse and Alfred Vail in the early 1830s. He wanted a way to send messages using electricity over telegraph wires. They assigned each letter of the alphabet and some symbols a unique combination of dots (short taps) and dashes (long taps). This allowed messages to be transmitted using simple codes, revolutionizing communication over long distances before phones or the internet.

Morse code
SOS

Morse code is like a secret language using sounds and pauses instead of words. Imagine tapping a pencil to talk to a friend far away. A short tap means a dot, a long tap means a dash, and pauses separate letters and words. So, "SOS" would be three short taps, three long taps, then three short taps again. It's a clever way to send messages without needing to talk or write!

"SOS" is a distress signal used to ask for help when someone is in trouble, like when they're lost at sea or in danger. It's like saying "please help me" in a simple and urgent way that people all around the world understand. It stands for 'Save Our Souls!'.

Sending SOS

Can you write a program to send SOS on one of your LEDs? You can send it using any colour you like. To use this, you'll need to use the 'delay' block. You'll find it in the 'Timing' group.

You'll need to use a combination of LED blocks and delay blocks to send your SOS (three short blinks, three long blinks, three short blinks again). You'll want delays less than 1 second, so you can change the '1' to a fraction of a second, or you can change where it says 'seconds' to 'milliseconds'. 1 millisecond is one thousandths of a second.

Experiment with the delays until you get a recognisable pattern, and then put your code in a big loop so that it flashes 'SOS' twice. You'll want a bigger delay between each 'SOS' than you have between each letter.

Sending SOS
Making sounds

The speaker is another example of an output as it can be controlled by your robot.

We can use the speaker to play notes.

The play block

You can find the 'Play music note' block under 'Sounds' (which is under 'Invent!').

Drag in one of these blocks and experiment with different notes and durations. The 1 in the note 'B1' refers to the octave, so low numbers are low pitches and high numbers are higher pitches. You'll probably want to use a higher pitch that is easier to hear. You'll also want to set the duration to a fraction of a second.

The play block
SOS buzzer

Can you change your 'SOS' program so it plays beeps for the 'dots' and 'dashes' on the speaker? Once you've done this, we want you to repeat your previous 'Save the Astronaut' challenge by playing an 'SOS' message after the astronaut is rescued.

So ... you robot should go forward, rescue the astronaut, turn around and return back to where it started, and then play the 'SOS' message on the speaker!

Playing a tune

Can you play a tune using a combination of notes? There are blocks to play pre-defined tunes but that's too easy! We want you to play a tune by specifying individual notes and durations. You can pick the tune. Feel free to keep it simple. How about 'Twinkle twinkle little star' or 'Happy birthday'?

The button

Let's now look at some input options. There's an inbuilt button on the main board as shown here. Let's find out how we can detect whether it's pressed or not.

The button
The button block

Start a new program and drag in the 'Button pressed' block.

The button block
The if block

Now drag in an 'if' block from the 'Logic' group. Make sure that the 'Button pressed' block is attached to the 'if' block like it is shown here.

The if block
The move block

Finally drop a 'move' block in within the 'if' block. What this should do is when you press the button, the robot should move forward 5cm.

Try it out ... does it work? You might find that it doesn't! Can you guess what the problem is? If not, we'll tell you in the next step!