In this article, we will introduce the code from lesson S of unit 8.2, which consists of three programs: Program Z, Program X, and Program Y. While Program Z is a simple script designed to reset the microbit, our focus will be on Programs X and Y. At first glance, these two programs appear to be similar, but they contain key differences that we will explore.
We start with Program Y because it closely resembles what students have encountered in prior lessons. In Program Y, you'll notice the sections labeled "on start" and "prev," along with several functions. These functions play a critical role as they break down the code into manageable pieces, outlining the key instructions needed to execute certain tasks.
One feature of Program Y is its use of if statements, which serve as counters. For instance, the code instructs the microbit to flash a heart symbol 10 times before proceeding to play a note, which is also played 10 times. Each time a note is played, the screen is cleared, and once complete, the program stops all sounds and displays a check mark. Though the functionality seems straightforward, the underlying code may appear messy and convoluted.
Comparatively, Program X also executes similar tasks but features a more compact structure. The more streamlined appearance of Program X is primarily due to its use of loops, which allow a section of code to repeat. Students have previously interacted with loops, such as the "Forever" loop, and they provide a more efficient way to tackle repeated tasks.
In Program X, we encounter a loop structure that repeats certain actions a specified number of times. Students can adjust the loop count easily, giving them flexibility in their coding. Additionally, we have various types of loops available, including those that check conditions or repeat at set intervals, which can be used when specific timing is required.
During the lesson, students are encouraged to modify one of the two programs to meet specific requirements, such as incorporating a timer that delays the start of a beeping sound until the microbit is in a designated location. Modifications can involve changing the number of repetitions for the heart icon or implementing delays within the code.
Students can use the existing delay functions to create pauses by transforming milliseconds into practical timing—for example, translating 20 seconds into 20,000 milliseconds. It's essential to experiment where this block should be placed in either program to achieve the desired effect.
Furthermore, students have the option to customize icons and sounds. They can explore a variety of built-in symbols or even create custom ones. Changes to the frequency and volume of notes can also be made during the "on start" phase or in the relevant code segments.
By encouraging students to tinker with the code, they can develop a deeper appreciation for programming and discover creative solutions to meet their specific needs.
The lesson aims to introduce students to two similar programs (X and Y) and encourage them to modify the code for specific functional requirements.
While both programs appear similar, Program X utilizes loops for a more efficient code structure, whereas Program Y relies on if statements that may make it more convoluted.
Students can use the existing delay functions to pause operations, adjusting values in milliseconds to control timing effectively.
Yes, students have the ability to customize icons, sounds, and their frequencies, allowing for creative freedom in their coding projects.
Students are encouraged to experiment with the programs' key components, such as changing the number of repetitions or adding delays, to better align the code with their objectives.
In addition to the incredible tools mentioned above, for those looking to elevate their video creation process even further, Topview.ai stands out as a revolutionary online AI video editor.
TopView.ai provides two powerful tools to help you make ads video in one click.
Materials to Video: you can upload your raw footage or pictures, TopView.ai will edit video based on media you uploaded for you.
Link to Video: you can paste an E-Commerce product link, TopView.ai will generate a video for you.