Introduction
Using a switch input and an IF block, make your own Morse Code machine to transmit any letter you like.
Tools
No tools specified.
-
-
So far, we have only used outputs - things that the Crumble board can change to HI or LO.
-
Inputs work in a similar, but opposite way - they can send a HI or LO signal back to the Crumble!
-
Our program then needs to decide what to do, depending on whether the signal is HI or LO.
-
The switch module is a great example of an input - when one of the switches is pressed, the port it is connected to will go HI.
-
-
-
Assemble your robot like the picture. The connections should be:
-
Red LED - A
-
Green LED - B
-
Switch - C
-
Buzzer - D
-
-
-
Using inputs is slightly more complicated - the Crumble needs to make a decision on what to do, based on the input.
-
We can make decisions easily using a IF block.
-
From the control menu, drag an IF block into your program underneath Program Start.
-
-
-
IF blocks have two parts:
-
Condition - this is the block you put inside the angled box of the IF block. The condition can be either TRUE or FALSE
-
Conclusion - this is just some blocks of code that are only run if the condition is TRUE - if the condition is false, they are skipped!
-
You're a bit like a computer that can use your own 'IF' blocks every day! For example, IF the bell rings, THEN the lesson is over.
-
Can you think of any more examples of IF blocks you use in real life?
-
-
-
To use the switch input in the IF block, we use the angled block that checks if a letter is HI or LO. Drag one into the IF block.
-
Change it so that it checks if the switch (C) is HI (pressed). Our condition is now finished!
-
Finally, drag an output set block into the conclusion of the IF block. Make sure it is set to turn on an LED.
-
Hold down the switch and click the program button. Your LED should light up! What happens if you don't hold down the switch? Will it light up if you press the switch after programming?
-
-
-
You would expect the previous program to turn on the LED when you press the switch.
-
You should have found that it only works if you hold the switch down when clicking program, or turning your robot off and on again.
-
What's wrong? Let's think through the program:
-
Start program
-
IF C is HI, set A HI
-
End program
-
Our robot only checks the switch once, then stops! We need to make sure it keeps checking, forever.
-
Add a do forever loop around your IF block, and check everything now works properly.
-
-
-
IF blocks are part of a family of blocks called conditionals - you can find them all in the control menu. Have a look through and see if you can guess what some of them do!
-
We're going to have a look at one more conditional, the IF/ELSE block.
-
IF/ELSE blocks start the same way as an IF block, but have another bit on the end - the ELSE part!
-
If the conditional is TRUE, the IF conclusion is run and the ELSE conclusion is ignored.
-
If the conditional is FALSE, the IF conclusion is ignored and the ELSE conclusion is run!
-
Have a go at building the example in the picture - before you program the robot, can you guess what it will do? Don't forget the do forever loop!
-
-
-
You may have noticed we have actually made our own Morse Code machine already!
-
By holding down the switch for a long time you can send a dash, and a short press would send a dot.
-
For this challenge, add some more blocks so that:
-
When the switch is pressed, the green LED and buzzer are on
-
When the switch isn't pressed, only the red LED is on.
-
-
-
Time for a harder challenge!
-
Using the Morse Code card from the first step, can you send a secret message to your neighbour?
-
Get them to decode it and see what they come up with - no speaking allowed!
-
-
-
A super hard challenge now - can you write a program that sends Morse Code for your initials (or even your whole name) automatically, but only when you press the button?
-
If you're feeling really clever, try and use some loops to reduce the length of your program if you need to send lots of dots or dashes in a row.
-
Cancel: I did not complete this guide.
One other person completed this guide.