Lesson video

In progress...

Loading...

Hello, everybody.

Welcome to Computing.

It's Mrs. Franzsen here.

It's really good to have you in my lesson today.

Let's get started with learning about physical computing.

By the end of this lesson, you will be able to write a programme which uses multiple outputs.

Let's look at our keywords for today.

The first keyword is motor.

A motor is a machine that converts electrical energy into mechanical energy.

Our next keyword is count-controlled loop.

A count-controlled loop is a chunk of code that repeatedly runs a section of the programme a certain number of times.

The third keyword is algorithm.

An algorithm is a precise sequence of steps that can be followed to do a task.

In the first part of the lesson, you will use a microcontroller to control a light and a motor.

This is a Crumble controller.

It is a microcontroller which can control outputs and respond to inputs.

In this lesson, you will connect a motor to your Crumble.

A motor can spin forwards, spin backwards, go at different speeds, and it can stop.

The blue coding blocks down at the bottom are examples of the kind of coding blocks that you use to control a motor.

We will be looking at these in more detail.

This example shows a model fairground ride controlled by a Crumble.

The Crumble is controlling the motor, which makes the model move.

Can you see how the motor is connected with wires that reach down to the Crumble and the battery pack? This is how the components should be connected.

The motor should be connected to the positive and negative motor pads next to the number 1 on the Crumble.

You can see that on the diagram here.

If we zoom in, you can maybe see it a bit easier.

So we've got the positive on the top and the negative on the bottom.

Let's do a check here.

Where should the motor be connected on the Crumble? Is it A, the A and B pads, B, the power and ground pads, or C, motor 1 pads? Pause the video to have a think about your answer.

Welcome back.

Where should the motor be connected on the Crumble? The answer is C, the motor should be connected on the motor 1 pads on the Crumble.

Well done if you got that one right.

These coding blocks are used to control the motor.

They are output blocks.

You can see that each coding block starts with the word motor.

The Crumble can have up to two motors connected.

The value here controls this.

So, in the block, it says motor 1, and you can change the 1 to be a 2 to control a different motor.

The 1 shows the command is for the motor connected to output 1 on the Crumble.

Click on the word in the centre to change the motor block directions.

So you can see, we are clicking on it and it is moving from FORWARD to REVERSE to STOP.

The command will cycle through FORWARD, REVERSE, and STOP, just like that.

The percentage value on the right-hand end of the block sets the motor's power.

You can see in this example, it is set at 75% motor power.

Download the combining inputs additional material.

Cut out the dancer disc and sticky-tack it onto your motor wheel.

This will help you check that your motor is connected properly and spins the correct way.

When you use the forwards motor command, the dancer disc should turn clockwise.

If your motor commands don't match your disc, switch the red and black motor lead connections on your Crumble.

Then it will go the other way.

Let's do a check here.

What happens if a motor's connections are reversed? A, it won't work.

B, it will spin in the opposite direction.

C, it will flash instead.

Pause the video to think about your answer.

Welcome back.

What happens if a motor's connections are reversed? The answer is B, the motor will spin in the opposite direction.

Well done if you got that right.

Okay, it's time for a task now.

The first step is to connect your battery pack, Crumble, Sparkle, and motor together correctly.

Use the wiring diagram here to help you do that.

Once that is done, I want you to create this programme and run it to test your motor.

Look closely at the order of the blocks and the different values used in the blocks to make sure that you're getting it right.

It's time to go and build your circuit, create your programme, and run it.

And once it's all working, you can come back to this video.

Welcome back.

Well done for all of your hard work during that part of the task.

Izzy says, "At first, my motor moved in the wrong direction, so I swapped the red and black motor lead connections, and then it worked." Well done, Izzy.

For the next part of the task, I want you to add the two sparkle blocks as shown below and run the programme again.

Off you go to finish that part of the task, and then come back to the video.

Welcome back.

Laura says, "While the Sparkle is lit, the motor runs at 75% power.

After five seconds, the light turns off and the motor stops." Well done for your hard work during that part of the task.

In the second part of the lesson, you will use loops to control outputs.

You might want to repeat some or all of the commands in your programme.

This loop block repeats the commands inside it forever.

This is also called an infinite loop.

You can see that the text on the block says do forever loop.

That is the program's way of explaining that this is an infinite loop.

Which programme would make the Sparkle LED light change like this? Look closely at the animation.

The answer is the first programme.

This programme uses the do forever loop to repeat the pattern.

Jacob says, "The do forever loop will run a sequence forever." Sam says, "What if you want a sequence to run a specific amount of times?" This is a count-controlled loop.

You can use it when you know how many times you want the commands repeated.

A count-controlled loop uses a value to control how many times the commands are repeated.

The value here is 10.

Let's do a check.

What does a count-controlled loop do? A, it runs commands a set number of times.

B, it runs commands forever.

C, it stops the programme.

Pause the video here to think about your answer.

Welcome back.

What does a count-controlled loop do? A count-controlled loop, A, runs commands a set number of times.

Well done if you got that answer correct.

Both loop blocks are control blocks.

They control how many times a sequence is repeated.

Let's do another check.

Which block is not a control block? Is it A, do 10 times loop, B, set sparkle to red, or C, wait 0.

5 seconds? Pause the video to think about your answer.

Welcome back.

Which block is not a control block? The answer is B.

B is not a control block.

Well done if you got that right.

An algorithm is a precise sequence of steps that can be followed to do a task.

You can follow an algorithm to create a programme.

Algorithms can help you come up with a detailed plan for your programme.

Algorithms can be presented in different ways.

This algorithm, algorithm 1, is a written algorithm.

The steps of the algorithm have been written down in order, and you can see that some parts are indented to show where the sequences go.

The algorithm reads: Spin the motor forwards at 50% speed Repeat the following 3 times: Light the Sparkle green Wait for 0.

5 seconds Turn the Sparkle off Wait for 0.

5 seconds Turn the motor off.

This is the second algorithm.

This is a sketched algorithm.

The algorithm has been drawn out using arrows to help you understand where each part will go.

It indicates here that the whole sequence will repeat four times.

That's why it starts with a 4x.

It has pictures of the motor and the Sparkle.

To show that the motor will turn on, the Sparkle will light up.

There will be a wait of one second.

The motor will turn off, and the Sparkle will turn off, and another wait of one second.

So that is a different way that you could present an algorithm.

Just because a programme runs doesn't mean there are no errors in it.

Even a programme that runs can still be wrong if it doesn't match the intended outcome.

Checking your finished programme against your algorithm is important for accuracy, accuracy meaning to make sure that everything is correct.

Okay, it's time for your task now.

The first step is to create an algorithm to make the dancer disc move and the light flash.

Your algorithm should use the motor, the Sparkle, and loops.

Think about changes and timing.

The second part is, when you've created your algorithm, programme and test it.

It's time to go and work on your algorithm and your programme, and then you can come back to the video.

Welcome back.

In the first part of the task, you had to create an algorithm to make the dancer disc move and the light flash.

An example of that is this algorithm.

It reads: Spin the motor forwards at full speed Repeat the following 4 times: Light the Sparkle orange Wait for 1 second Turn the Sparkle blue Wait for 1 second Turn the Sparkle off Turn the motor off.

Your algorithm might be different from this example, and that is fine.

You might have different ideas on how to use the Sparkle or the motor or your loops.

In the second part of the task, I wanted you to use your algorithm to programme your sequence and then test it.

Here is an example of my programme that uses the motor and the Sparkle light.

Remember that your programme might look different from this, and that is okay.

You have worked really hard in this lesson today.

Let's go through our learning on combining inputs.

The Crumble is a microcontroller that can be used to control components that are connected to it.

A motor is a machine that converts electrical energy into mechanical energy.

A motor can be connected and run through a Crumble.

You can use loops to repeat sequences of commands.

A count-controlled loop can repeatedly run a section of code a certain number of times.

Code can be written by following an algorithm.

Well done for all of your effort during this lesson.

It was great to have you here, and I hope to see you again soon.