09 Mission Instructions
6. Record Your Message, part 1
Morse code is entirely based on time. Dots are the shortest option, and dashes are three times longer! When we are recording our Morse code message, we'll press the button quickly to represent a dot, and we'll hold the button down for nearly one second to represent a dash. Then we'll remember to pause extra long between each letter of our message.
If we want our robot to repeat our message back to us, it will need to have some data about how long each part of the message was. Luckily, the GoPiGo has a timer built into it, and we can write a program that tells the timer to reset every time the button changes from not pressed
to pressed
and back again.
To do that, we'll be playing with our conditional statement. Let's start by imagining what we're going to do:
First, we'll turn our robot on (but we won't be pushing the button yet).
Then, we'll push the button and reset the timer back to zero.
Then, we'll release the button and reset the timer back to zero.
And we'll repeat this over and over until our message is finished.
Since we don't need the timer to record anything between when we turn on the robot and when we push the button for the first time, let's start our conditional statement there.
If the button is pressed,
DO...
- Reset the timer.
- Wait until the button is not pressed anymore.
- Reset the timer again.
- Wait until the button is pressed again.
Here is what our program looks like. What does yours look like?