Activity 5– KISS - Keep it Simple with Subroutines |
One of the most appealing things about programming languages is the ability to write action steps (or code) once and then reuse that set of actions over and over. In programming, this process is accomplished with Subroutines. Subroutines allow you to create a group of Tiles that you can use again and again as needed.
In our previous activity we drew a circle by drawing one quarter of a circle and then copied those same tiles 3 more times to draw the rest of the circle. If we were using a Subroutine, we could have 1 Subroutine that drew one quarter of a circle, and then we could just run that Subroutine 4 times.
In the Scribbler Program Maker, the symbol for Subroutines is the Gear. Anytime you see that, it means that feature can run a Subroutine. In fact, you have already been using a Subroutine in all of your programs. The Green Gear at top of the program edit is the Main Subroutine. The Main routine is always green. In this image, the Yellow Gear is a different Subroutine that is used to turn on the lights of the Scribbler.
Note: To learn more about inserting and running Subroutines, view Creating/Calling Subroutines section in the Scribbler Tips documentation.
In our first use of Subroutines, we are going to use the lights to flash the signal, S. O. S. which is the universal signal for HELP. To do this we are going to write 2 Subroutines, one for the letter S and one for the letter O. Then we will run the S Subroutine once, then the O Subroutine, then the S subroutine again. Let’s get to it!
First off, we need to know how to represent HELP, or SOS with lights.
Pre-Activity Check List:
Activity Steps:
Let’s take a closer look at this program before moving on. You will notice that there is nothing in between the Green Gear. Also, if you look closely at the yellow Subroutine, it looks like it is transparent. The reason that the yellow Subroutine is see-through is because we have not told the Green Gear to run the yellow Subroutine. We will do that after we make our next subroutine.
· Hint: Use the copy/paste to copy the Tiles in the yellow subroutine to the orange subroutine and then you can just change the timer! · Your program should look like this:
Now that we have our two light flashes (Fast Flash and Slow Flash), we need to make new subroutines to call the flashes so we can make the letters SOS.
Optional Activity
Create a program using subroutine to send your initials in Morse Code. You can use your favorite search engine and search for “Morse Code letters” to find out how your initials are shown with lights.
>>Update the Lesson Worksheet with your observations. |