Skip to main content

Introduction

Using a switch input and an IF block, make your own Morse Code machine to transmit any letter you like.

  1. So far, we have only used outputs - things that the Crumble board can change to HI or LO.
    • 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.

  2. Assemble your robot like the picture. The connections should be:
    • Assemble your robot like the picture. The connections should be:

    • Red LED - A

    • Green LED - B

    • Switch - C

    • Buzzer - D

  3. Using inputs is slightly more complicated - the Crumble needs to make a decision on what to do, based on the input.
    • 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.

  4. IF blocks have two parts:
    • 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?

  5. 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!
    • 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?

  6. You would expect the previous program to turn on the LED when you press the switch.
    • 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.

  7. 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 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!

  8. You may have noticed we have actually made our own Morse Code machine already!
    • 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.

  9. Time for a harder challenge!
    • 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!

  10. 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?
    • 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.

Finish Line

One other person completed this guide.

Tech Camp

Member since: 10/03/2012

118 Guides authored

Team

Tech Camp Staff Member of Tech Camp Staff

Community

3 Members

139 Guides authored

0 Comments

Add Comment