Disciplinary Core Ideas
- ETS1.A: Defining and Delimiting Engineering Problems: Possible solutions to a problem are limited by available materials and resources (constraints). The success of a designed solution is determined by considering the desired features of a solution (criteria). Different proposals for solutions can be compared on the basis of how well each one meets the specified criteria for success or how well each takes the constraints into account. (3-5-ETS1-1)
- ETS1.B: Developing Possible Solutions: At whatever stage, communicating with peers about proposed solutions is an important part of the design process, and shared ideas can lead to improved designs. (3-5-ETS1-2)
- Tests are often designed to identify failure points or difficulties, which suggest the elements of the design that need to be improved. (3-5-ETS1-3)
- ETS1.C: Optimizing the Design Solution: Different solutions need to be tested in order to determine which of them best solves the problem, given the criteria and the constraints. (3-5-ETS1-3)
- Learning to integrate new ideas, subroutines, with old ones, motors, LEDs and buzzers.
- What advantages does coding with subroutines provide?
Depth of Knowledge Levels Addressed
- Level 1: Recall and Reproduction
- Level 2: Skills and Concepts
- Level 3: Strategic Thinking and Reasoning
- Level 4: Extended Thinking
Barriers to Learning
- Poor understanding of previous programming concepts
- Inability to grasp abstract concepts
- Students will learn about subroutines as advanced methods of implementing previous coding ideas.
- Creating several subroutines for individual tasks that have already been covered i.e. waving, blinking, siren noises etc.
Final Assessment, project or product
- Having the robot do several different actions one after the other with the use of subroutines.
Step 1: Subroutines (60 min)
In Ardublock we can code using what are called subroutines, which can be found at the bottom of the control tab.
The two subroutine blocks available are the subroutine commands block and the subroutine block ( which I will refer to as the subroutine run block). Upon closer inspection of the two blocks I can see that only one of them fits into the loop do:
The subroutine commands block acts as a place to hold code. If we subroutine commands block contains other blocks in it we can use the subroutine run block to reference that code later. Here is an example:
Inside the subroutine commands block you can see I have recreated the blinking light code. Also, I have renamed the subroutine commands block to flash. The exact same has been done to the subroutine run block, which also reads flash. When the code attempts to run the loop do sees flash and tries to find a subroutine command block with the same name. If it is successful in finding an identically named subroutine command block it will essentially insert all blocks within that subroutines command block into the code. Looking above you can think of the block inside the loop do as a placeholder for all of the blocks inside the subroutines command block.
The real question is why is this useful? Haven’t we just made more work for ourselves? Well, yes and no. In the example above the use of subroutines is unnecessary, but as we aspire to create more and more complex code subroutines become a powerful tool. Take a look at the list of tasks I want my robot to do below:
- Wave its right hand
- Make a siren noise for several seconds
- Wave its right hand again
- Dance for a few seconds
Doing this without subroutines will take much work and be difficult to keep organized. However if I take the time to create subroutines for each of these actions I can clean up the code inside the loop do tremendously:
Notice that in the code above some subroutines are used multiple times. This is done while only making one subroutines command block per each distinctly named subroutine. You can see that in this case, where some subroutines are run multiple times, having subroutines is much better than not. In addition to that the code is much easier to read and understand.
- Subroutine: A set of instructions designed to perform a frequently used task. In Ardublock the subroutine blocks consist of the subroutine commands block, which holds the instructions, and the subroutine (run) block, which fits into the loop do.
- Using subroutines is a two step process. Explain the two steps.
- How is naming subroutines significant?
- What was hard in today's class?
- What was fun about today's class?
- What did you learn about yourself?
- What would you like to improve?
- How can what you learned impact those around you?