Loading...
Hello, everybody.
Welcome to Computing.
My name is Mrs. Franzsen and it's really good to have you in my lesson today.
Let's get started with our learning all about physical computing.
By the end of this lesson, you will be able to create a physical project that includes selection.
Let's look at our keywords for today.
Our first word is algorithm.
An algorithm is a precise sequence of steps that can be followed to do a task.
Our next keyword is repetition.
Repetition is a part of a programme where one or more commands are run multiple times in a loop.
Our third keyword is debug.
Debugging is finding and fixing errors in a programme.
In the first part of the lesson, you are going to create an algorithm for a coding project.
This animation shows a model carousel controlled by a Crumble microcontroller.
The Crumble is controlling the motor, which makes the model move.
You can see that I've highlighted the motor in the animation.
Your task is to programme a carousel model that uses at least two different output devices.
How could you use selection to do this? Pause the video and have a think about that.
Well done for thinking about that question.
Let's look at some answers.
Jacob says, "If the button is pressed, then the motor will power to 100%." Sam says, "If the motor has started, then flash the Sparkle light yellow and red." Izzy says, "If the motor is off, then turn the light purple." All of these are examples of using selection in projects.
In a carousel programme, the components are programmed to carry out actions when a condition has been met.
This is selection.
Let's take Jacob's idea for his project.
Jacob says, "If the button is pressed, then the motor will power to 100%." An algorithm is a precise sequence of steps that can be followed to do a task.
Jacob's idea can be written as an algorithm.
The algorithm reads forever, if push button switch is on, then set motor forward at 100% power." Why does this algorithm start with forever? Pause the video and have a think about that.
Laura says, "The device needs to repeatedly check if the condition has been met." That is why we use forever.
This is called repetition.
Okay, it's time for a check here.
I want you to complete the definitions.
We have an algorithm is, dot, dot, dot.
And repetition is, dot, dot, dot.
Complete the definitions, pause the video to work on that and then come back and I'll show you the answer.
Welcome back.
Let's look at the answers together.
An algorithm is a precise sequence of steps that can be followed to do a task.
And repetition is a part of a programme where one or more commands are run multiple times in a loop.
Well done if you got those right.
What is the condition in this algorithm? Can you see it? Izzy says, "The condition is if push button switch is on." If the condition is true, then the action will trigger.
What is the action in this algorithm? "The action," Jacob says, "is the motor turning on in a forward direction at 100% percent power." The algorithm has been written with indentation to make it clear that the commands are linked and you can see where the purple arrow is, that the second line starts a bit more to the right and then the third line starts even more to the right, so that is indentation to show that the commands are linked.
Let's do a check here.
Why do you write algorithms using indentation? Is it A, to show the outputs that you're using, B, to show that the commands are linked, or C, to make it neater?" Pause the video and think about your answer.
Welcome back.
That was good effort working on that question.
The answer is, the answer is B.
We write algorithms using indentation to show that the commands are linked.
Well done if you got that one right.
Let's look at these two algorithms. We've got algorithm A and we've got algorithm B.
Which algorithm do you prefer? Why? Pause the video and have a think about that.
This is also a good question if you've got someone with you to maybe discuss your answers with someone else.
Welcome back.
Let's look a bit more closely at these two algorithms. Algorithm B.
This algorithm is more clear and precise.
It uses indentation to show how the commands are linked.
It uses details like timings, the number of repeats, the motor direction, and the power.
All of these reasons are why algorithm B is the better algorithm compared to algorithm A.
Okay, it's time for your task now.
I want you to write an algorithm which uses selection to control a model of a carousel that uses at least two output devices.
Remember to use selection to make sure conditions are repeatedly checked to see if the condition has been met.
That's your repetition.
To include the waiting and to turn all of your outputs off at the end.
Okay, it's time to go and work on that algorithm.
You can pause the video here and when you come back, I'll show you a finished example.
Welcome back.
That was some good effort working on your task.
Let's have a look at the answer together.
This is an example algorithm.
Yours might look a bit different, but as long as you've got the same features in yours, you've done a really good job with this.
So it starts with the forever loop, because we want this to continually be checked, okay? We don't want it to only run once.
After the forever loop, it says, "Do the following if the button is pressed.
Repeat three times.
Light the Sparkle green for 0.
5 second.
Turn the Sparkle off for 0.
5 seconds." So that is going to repeat three times, and then it says, "Spin the motor forwards at half power, pause for 10 second, spin the motor backwards at half power, pause for 10 second.
Stop the motor." And then at the end, it's going to repeat this section three times.
Light the Sparkle red for 0.
5 seconds.
Turn the Sparkle off for 0.
5 seconds.
And that last section will repeat three times, okay? Well done for all of your hard work on this task.
In the second part of the lesson, you are going to write and debug code to control a model.
Now that your algorithm is written, you need to create your basic model structure.
You should place your components into your model and ensure they're all connected.
You can see in this photograph that there is a battery pack, there is a Sparkle LED, There is a motor at the top, and just out of sight behind the cardboard pillar in the middle where all the crocodile clips are connecting, that is where the Crumble is on this model.
You can use a label diagram of your model as well as a wiring diagram to help you construct it.
You can see we first got a labelled diagram here of the model.
That's the sketch.
And then the second image is the wiring diagram.
Izzy says, "The model diagram helps with constructing your physical model." You can see here that there are measurements and labels to show where each element should go.
Sam says, "The wiring diagram helps you to connect the components together," and you can see here we've drawn in the Sparkle, the push button switch and the motor, and also connect them all together to help us do this with the physical component.
If you do not have your own diagrams, you can use these.
Let's do a check here.
Why is a wiring diagram useful when constructing a model? Is it A, it helps you construct your physical model, B, it helps you know how to spell different components, C, it helps you connect the components together, or D, it helps you know what colour wires to use.
Pause the video and have a think about that.
Well done for having a go at that question.
The correct answer was C, a wiring diagram helps you connect the components together.
Look at this algorithm and code.
So on the left, we've got the algorithm, and on the right, we've got the code version of this algorithm.
The code is based on the algorithm.
What parts can you see in both? You may want to pause the video here to have a close look at the code and at the algorithm.
The first part that is similar is the forever loop.
You can see the forever loop starts at the top of the code and the algorithm.
That is the repetition there, the forever loop.
You can see that the algorithm and the code both check the condition.
The algorithm does this by saying if the button is pressed and in the code, you can see very similarly, we've got a if then and if loop with the A is HI condition in there, so if the A is HI, A is HI is the Crumble word for the Crumble phrase for the button being pressed.
Lots of the actions are replicated as well, so you can see our actions start with the repeating three times, then some motor movements, and then repeating three times at the end and both the algorithm and the code do that.
The same sequences are used in both.
Use your algorithm to guide you in writing a programme to control your carousel model.
Test your programme often as you go.
Don't wait until the end.
You may find that you need to make some changes to your algorithm as you code, and that is fine.
Programmers write code in different ways, but your programme should still contain your concepts from your algorithm.
Let's do a check here.
Your programme can be totally different from your algorithm.
Pause the video to think about that.
The answer was false.
Why? If you change too much, your programme might not work the way that you want it to.
Your algorithm and your programme should match as much as possible.
Well done for thinking about that question.
Do you remember what finding and fixing mistakes in a programme is called? Laura says, "Finding and fixing errors in code is debugging.
You should do this often." As you work on programming and debugging, you might find that the USB cable connecting your computer to the Crumble is in the way.
Sometimes you might have to unplug it while you test things.
When your programme is complete, unplug the USB cable.
Okay, it's time for the final task.
I want you to use your algorithm to guide you in writing a programme to control your carousel model.
When your programme is complete, you should test it to make sure it works as you planned.
If the button pressed, selection, does everything work properly? Debug your programme to fix any errors.
Okay, it's time for you to go now and work on your programme.
Use your algorithm to guide you with that.
When you come back to the video, I can show you a finished example of the code.
Welcome back.
I hope you have enjoyed building your model and writing your algorithm and then coding your programme.
Here is an example of the finished task.
You worked really hard writing and testing your algorithms in this lesson.
Let's summarise our learning.
Selection allows a programme to carry out specific actions when a condition is met.
To keep checking whether a condition has been met, repetition is used.
When designing a physical project, an algorithm is created to outline the steps needed.
The algorithm can be used to write a programme to control a model carousel.
While coding, debugging is an essential process to find and fix errors to make sure the programme works as expected.
I've really enjoyed having you in my lesson today and I hope you've enjoyed working on your programme too.
I hope to see you again soon.