video

Lesson video

In progress...

Loading...

Hi, I'm Allan your computer teacher for this unit and this is physical computing lesson two.

You will need your micro:bit again today and a USB cable to connect it to your computer.

You also need a couple of crocodile clips, and you'll need a LED.

Okay, so we're going do some cool stuff with those today.

As always turn off all notifications cause you don't get disturbed when you're doing cool physical computing, remove any other distractions that are nearby and when you're ready we can get started.

Okay, in this lesson we're going to write programmes that use the GPIO pins to generate outputs and receive input.

So firstly, look at this picture on the right-hand side, how can you light up the LED? Okay, so you can pause the video if you want to think about it and we'll resume in a sec.

Of course, if you wanted to light up the LED you'd form a closed circuit.

So the way you would do that is you join up those two red crocodile clips that are not connected, they're connected to the positive end of the battery.

And the positive is connected to the long leg of the LED, which is important because power only flows through an LED one way.

And the shorter leg is connected to the negative term of the battery.

Okay, as we know from previously when we discussed the features of the micro:bit, the micro:bit can be connected to other components through those GPIO pins to make part of a circuit.

So as we said before, GPIO means General Purpose Input Output.

And you can see on the diagram, I've got a couple of things there.

And as I said at the beginning of the lesson you need crocodile clips and an LED for this lesson to be able to complete some of the tasks.

So through the pins, your programmes can control the power in a circuit which would be the output and through the pins, they can detect power in a circuit which would be input.

So those GPIO pins on the micro:bit are referred to us pin0, pin1 and pin2.

And they're nicely kind of labelled on the micro:bit as well as notes one and two.

There are smaller ones in between as you can see, but we're not going to be using those in these lessons.

But if you had a special adapter to dock your micro:bit into, you could make use of extra GPIO pins too.

I'm going to show you a little bit of a demonstration on how to use the terminals, the GPIO pins with some crocodile clips.

Okay, so here's mine set up already as you can see and I've got the code flashed onto it.

And for ease of recording, I've attached some crocodile clips to pin zero and ground, and just in the same way as if I was to touch it with my finger.

So when I touch, and make that closed circuit as we saw at the beginning, the smiley face appears.

And then when the circuit is broken, the sad face appears.

Your task now is to kind of replicate that using the worksheet.

You can complete the task on writing a programme that will sense touch.

So it works in a similar way as to having the crocodiles clips connected.

You can pause the video and complete the task.

How did you get along? Well, when you saw my demonstration, I kind of mixed the two up between something that would touch the two pin, the two terminals here for zero and ground.

And I use the freezer filming I can attach crocodile clips to it, it's exactly the same.

Any contact between the wires if you were to attach it to the three volt pin as you can see on the diagram.

And the one pin would allow a circuit to be formed, and current to flow between the power pin and the input pin.

So you're going to have a task now to do using this kind of method.

So you can pause the video, it's task two which is a makeshift switch and you can complete the task.

Okay, so in this task you were required to connect some crocodile clips to pin one and the three volt pin, and record some answers as to when you take the coding and run it.

When you touched the two clips together as supposed to when you didn't touch the two clips together.

And what you should have found is when the switch is off, or the crocodile clips are not touching, you'll get a zero result.

When the crocodile clips are touching which means you have formed a circuit, then you get a one as a result.

The next part of this task was to modify the programme so that when your crocodile clips were connected, then you were showing some kind of image for YES which will be a tick.

And if the crocodile clips were not touching, then it would display NO or a cross the image for now on that.

And you can see a sample solution on the screen for that code on this slide.

If you didn't manage to get that working, you can pause this as before, you know, make sure you're typing the code to get a working solution before you move on.

Really important that you feel that you've achieved that.

And you understand that it's, any mistakes that you've made, you kind of know why you made them or you know where they were made.

So, type that thing if you didn't manage to do so or get that right previously.

Okay, so now I'll demonstrate how to light up an LED using a micro:bit crocodile clips and an LED.

Okay, so I'm in And I'm going to show you how to get the LED lighting up.

So with all programmes using the micro:bit from micro:bit import star to import everything.

I'm going to put this in a while loop, while true so it does whatever I'm asking it to do forever.

I'm going to have a variable called out value.

And I'm going to set that equal to integer with the value of button a whether it's pressed or not.

So if button a pressed, then it would be a one.

And if the button a isn't pressed, then it will be a zero.

Don't forget to put the correct amount of brackets there as well.

I'm thinking write that value or write a value to the pin zero.

Here we go, so I'll send that out value to pin zero So that will activate the circuit depending on whether it is zero or one.

It will send power if it's a one and if not it won't to the LED.

And also just as a little visual display on the LED matrix.

I'm also going to put that out value out to display there.

So I'll flash this and you'll be able to see it working.

Okay, you can see here, I've already got my red crocodile clip on pin zero and I've got my ground pin my black crocodile clip on the ground.

Here's my LED, this is a long leg.

I'm going to attach that to the positive crocodile clip and the negative there.

It's showing zero because button a isn't pressed.

As soon as I press button a, it shows a one and the LED lights up.

If you let go, it's a zero.

So by detecting the input of this button, it's getting the value from the button, sending that, assigning that to a variable.

We're sending that variable to the pin, and that pin in turn is creating a circuit.

She kind of cool.

Right, so now it's your turn.

You saw my demonstration of how to light up the LED, there is a worksheet to complete for this task with some code there.

See if you can get your LED lighting up.

Okay, did you manage to work out how that programme works and get your led lighting up? Well, as you can see from the programme on the left-hand side there, we're creating an out value variable.

And the value of that is an integer, and it will either be a zero or a one depending on if button a is pressed or not.

And then what's happening to pin zero is it's writing that value to pin zero or making, sending that value to pin zero.

And then obviously if it sends a zero, then the LED will be off.

And if it sends a one, the LED will be on.

Don't forget there is a quiz to complete at the end of every lesson.

And we'd love you to share your work with Oak National.

So if you've got any pictures or images of your work that you've been doing with your micro:bits, then you can share it.

Please ask your parent or carer to share on Instagram, Facebook or Twitter tagging @OakNational and #LearnwithOak and I'll see you next time.