You have turned-in this assignment. You can review the lesson and see your previous answers.

Lesson video

In progress...

Loading...

Hi, my name's Mr. Brown and welcome to today's lesson about microcontrollers.

I'm looking forward to working with you today talking about microcontrollers, about variables, and all sorts of different things.

And we're gonna be looking at Tinkercad and how we can use Tinkercad and micro:bits.

All right, without further ado, let's move on to the lesson outcome and the key learning points for today.

And here is today's learning outcome.

So today we're going to be learning to create, simulate, and download a simple micro:bit programme.

There are four keywords today.

Programme, a list of instructions to a computer.

Coding blocks, that's language used to write instructions to a computer.

Variable, that's a place to store data in a programme.

And debugging, that's finding and solving problems in a programme.

And here is the lesson outline.

There are two learning cycles today.

The first learning cycle is micro:bit programme for a data logger, and the second is downloading a micro:bit programme.

Of course, we're going to start with learning cycle one, micro:bit programme for a data logger.

Now, for a micro:bit to work, we need to give it instructions to follow.

Now, these instructions can be written in coding blocks, and you can see there there's a whole variety of coding blocks that you may well be aware of anyway in work that you've done with coding in the past.

We've got four different coding blocks there with other coding blocks inside and there's different instructions.

And all of these, we're not gonna go through that particular coding block for the moment, but we are going to be thinking about using these coding blocks to create a programme, because the whole list of instructions is what we call a programme.

Sometimes it's called an algorithm within computing, but Tinkercad calls it a programme.

So there you can see we've got the individual coding blocks, and when they're all put together, that creates a programme.

Now, a data logger programme for logging traffic, that can be created within Tinkercad.

Check for understanding.

What is a computing programme?

Is it A, a list of components in a computer; B, a list of instructions to a computer; or C, a list of circuits in a computer?

Which do you think?

That's right, it's a list of instructions to a computer.

Well done.

Now, for each type of traffic in the data logger, we need a variable.

So every type of traffic that goes past is a variable.

It's something that might change.

Now, a variable is a place to store data, such as how many cars passing by in 10 minutes, and this programme has four possible variables: a bike, a bus, a car, and a truck.

And you can see those there in those four purple variables that are there, bike, bus, car, and truck.

And then there's two coding blocks underneath which is set and change.

Now, what we need to do first was set up these variables, and to set up these variables, we need to do one at a time.

We're gonna go through how to do that now.

So, the first thing you need to do is to find the Variables blocks in Tinkercad.

You then need to set up a variable for each type of traffic, and you can see there that this pupil is actually setting one up called bicycle.

So you just need to click on New variable name and bicycle.

Check for understanding now.

What type of coding blocks will need to be set up for each type of traffic?

Are they gonna be called inputs, basic, or variables?

Which do you think?

That's right, well done.

It's variables.

Right, so moving on with our instructions.

So we've now set up our four or three or however many variables you're choosing to do.

We've set those up.

Now, what we need to do is to think about the programme and the coding blocks that we are gonna need to use in a bit more detail.

So we're gonna use the on start and we're gonna set bike to zero.

All right, so add set bike.

So remember we talked about those variable blocks at the beginning.

We're going to just drag one of those over to the on start block that should be in your coding block space.

So what you need to do is drag that over, and then to on start so the counter begins at zero.

Basically what you are telling the computer is when we start this, we want the number of bikes to be zero.

We don't want it to start at 14 or anything like that.

We want it to start at zero so that we can start our our counting at zero.

That's what you are telling the micro:bit to do.

The next one is we're going to put show LEDs.

So we're gonna bring on button A pressed, so we're gonna bring that orange coding block over, and we're gonna put show LEDs into that and then we're gonna put on button A pressed.

So again, just to go through what that means.

It means that when button A is pressed, then the LEDs on the micro:bit will show that design, which looks like a small B.

We're gonna then put the two coding blocks, we're gonna put another coding block, not set, but change.

So we're gonna put change bike by zero, we're gonna put that as the counter.

So that purple one, not the set but the change.

Basically what you're saying to the micro:bit is that we're going to change the bike counter by zero and you're gonna show the LEDs.

So when button A is pressed, that's when we see a bike, then we change it by zero and do the LEDs.

Now, you might have noticed that there's a bit of a problem with that, because we don't want to change bike by zero.

We want to be counting the bikes.

Every time we see one, we want to add one to each counter.

And that's why we then need to make sure it's not change bike by zero, but change bike by one.

So that's really important that you actually make sure that when it's the change bike coding block, it's changing it by one.

Remember, set bike, that needs to be zero 'cause we're gonna start at zero.

But then this second purple one is all about increasing the number of bikes by one.

Okay, we're gonna also add another coding block here, which is wait 1 sec.

Now, all that means is that the display of a bike comes up for one second.

And then we're gonna clear the screen, 'cause we're going to get rid of that ready for the next piece of traffic or that next type of traffic to come across.

So let me go through what is happening with that whole coding block there.

So the button A will be pressed.

That will increase the count of bikes by one.

And then on the LED as an output there will be a small B.

That will be there for one second and then it will disappear and clear.

Now we go through and we do the other types of traffic.

So you can see the coding there has been done for bike on the left-hand side, and then it's pretty much identical for all the other types of traffic, except the LEDs change, and of course, we're looking at bus rather than bike or car rather than bike and truck rather than bike.

Of course, your designs might look quite different to that depending on what type of traffic you've decided to use.

Check for understanding.

Which of these codes is best for counting the number of bikes travelling down a road?

Is it A, B, or C?

Which do you think?

That's right, it's C.

Well done.

Right, let's go for some more coding blocks now.

So the data in each of the variables needs to be displayed.

So we're now moving on to, we've got the data logger, we've got the micro:bit, sorry, being a data logger and it's counting up by one each time, but where do we get the results from?

How do we actually find out what the total is?

Now, there's a very clever way of doing this, because what we can do is we can press buttons A and B at the same time and that will be our results.

So that will display what all the results of the variables are.

So we'll go through this again step by step.

So on button A and B pressed, that's where we need.

So remember we had on button A pressed or on button B pressed for another type of traffic?

This one is on button selecting A and B.

And then we right click and duplicate the show LEDs bike code from earlier.

I mean, you can start from scratch again, but this is just a nice quick way of doing it.

And then you can place that bike code into on button A plus B coding block and replace clear screen with another wait 1 second.

So I'll explain why in a moment.

So, before we go any further, what we're gonna do is we can combine a show number.

Now, you need to go from the inputs with the bike variable.

So remember we made those bike variables, the truck variables, the bus, and car variables earlier?

You can actually put those in.

Instead of a show number, you can actually use those as something to be shown.

So what you're doing there, and when it says show number bike by putting the bike inside where that zero is, what you're telling the micro:bit is when we press buttons A and B, I want you to show the total number of bikes that have been counted.

And then when we put it in, it looks a bit like this.

So we've got on button A plus B, so when A and B is pressed, then we're going to show the LEDs for bike.

We're gonna wait for a second.

We're gonna then show how many bikes have actually gone past and then we're gonna wait another second.

So you can see where everything goes.

It's a nice sequential order.

What we do now is we take that piece of code and then we repeat it for bus.

So we're going to include within the same part, within the same on button A and B press, this is really important that you don't do separate ones for this.

It's all together.

And we do the same as we did for bike for bus and car and finally truck.

And if you have a look at that one for truck, that looks like a lot of coding, but it's just repeated in a very similar way.

And once you've got the bike, you do the same for bus, same for car, same for truck, and you put it all together.

So let's go through that big bulk of code there on the right-hand side and let's go through exactly what's gonna go through step by step.

So you can see the code, but let's also talk about what is actually going to happen.

So you've done your data logging, you want to get your results, so you press buttons A and B together and then a small B will appear.

It will be there for one second.

And then the number of bikes that you've counted will appear.

That will wait one second.

And then a large B will appear.

That will be there for one second.

And then that will show the number of buses that came.

That will wait one second.

And then a large C will come, wait one second.

Then the number of cars and then that will wait one second.

And then a large T will appear and that will wait one second.

And then will show the number of trucks and that will wait one second.

And you may have noticed right there at the bottom we've got a clear screen, so then it just clears the screen.

And of course, if you wanted to get those results again, you just need to press A and B again and then the results come back up onto the screen.

Right, your turn now.

So we're going to split this up into different sections.

So we've gone through all of the instructions in detail.

What we've done is we've put the code there that you need to create.

If you need to go back through the slides and see the step by step then do that way, but this is the finished code that we are hoping that you will be able to produce.

So this being the finished code, what you need to do is you need to do your on start for bike, your on button A for bike.

And then the second one, this one is about buses, and again, you can make your own designs and decide how you're gonna do this.

This is just one example.

And then we've got, now this time for bus, button B is going to be pressed, and that will change bus by one, and then we'll have that large B and then wait one second, then clear the screen.

For car, this one is gonna be tilted to the left.

So when the micro:bit is tilted to the left, that will show a C when you see a car, and then if you're gonna see a truck, then you tilt it to the right-hand side.

Okay, right.

Let's do one thing at a time and let's get this programme done first of all already into your Tinkercad workspace code editor.

Okay, good luck.

Hope it all goes well.

And remember, you can always go back through the slides, and this is an example of a code.

Do be creative and do go off in your own direction.

Right, well done.

Looking forward to seeing what you get up to.

Off you go.

Okay, well done.

So you've done Task A one.

We're now gonna go onto A two and three.

So A two, this time I want you to include a programme to display the results.

So remember we talked about that long bit of code that's all part of that A plus B button?

Well, what I've done there is just put on the left-hand side the full code and then I've enlarged just one section of it so you can clearly see what it looks like.

So, now you need to have a programme to display all of the results.

And of course, don't forget, it's really important that you name what you're doing in Tinkercad, because you'll be using Tinkercad for so many different things, it's really important that you think of a really useful file name for this particular project.

So I'll let you and your teachers decide what that's going to be called, but in the meantime, this is the last part of your programming that you need to do for Task A.

Right, okay, off you go.

I'll give you an example and some feedback about what it should look like at the end.

You might think it looks a bit confusing with lots of different things all over the place, but be logical about it.

We've done eight bits of coding already in the previous A one task.

We've got one more piece of coding here and then it's all completed.

Right, well done.

Off you go.

Looking forward to seeing how you get on and I'll give you some feedback in a moment.

So here we are.

Jun has created his code for each of the traffic variables, and you may notice that he's actually done it in a slightly different way to the way that was presented in the previous slide, and that is that he's actually put his into a square.

So he's put two above and two below rather than having them all in one line, and that's absolutely fine.

It's not a problem to do it like that so long as that all the code is accurate.

He then finished his programme by adding the coding blocks to display the results.

So remember that long piece of code that we talked about earlier, and that was task two.

And there you've got the finished code.

Hopefully yours looks something similar to this.

It might look like it's in one long line.

It depends upon how you've used it, and you can always change it to look like this or do it whichever way that you've actually done it, but hopefully you've been thinking about how to be creative too.

Now, just to zoom out a little bit more so that you can see what your workspace and coding editor might look like.

This is Jun's Tinkercad workspace and coding editor and his looks like this.

So hopefully your screen that you've got in front of you will look something similar to this, and you can see all of the different codes there.

In the previous slide I'd literally just copied a screenshot of that, but now just zooming out, you can see where everything is.

We've got the micro:bit there, we've got the blocks, we've got the coding editor, and we've got all the different parts of the programme which we have created today.

Right, well done.

Glad you've done so well.

Hopefully you've got something that looks similar to this.

Might be a bit creative, you might have done something slightly different, but I'm sure the elements of the coding blocks are there, so well done.

Let's move on to lesson cycle two now.

That's downloading a micro:bit programme.

So we've made our micro:bit programme, we're now going to download it.

Now, before you download it, it is really worthwhile to actually simulate and test it.

And this can be done in Tinkercad by clicking start simulation as we've just identified there.

Check for understanding.

Which button tests a micro:bit programme in Tinkercad?

Is it code, send to, start simulation, or code editor?

Which do you think?

That's right, it's start simulation.

Well done.

Now, unfortunately, Jun's had a problem with his programme and it doesn't actually work in the simulation.

Can you have a look and think why?

So what he has to do is he has to go back at the programme, debug the coding block, so that means to find the issues, and just go through one block at a time and decide where there might be a problem.

Now, maybe you've been able to find out where the problem is already, but it's about finding and solving problems in his programme.

That's what debugging means.

He realised, as you've probably already found out, that he forgot to change the count in the variable code.

So he needed to change the zero to a one, so that at the moment, change bike by zero means it's not gonna count anything at all.

It's not going to increase by anything.

It's counting in zeros.

Whereas he's now saying count every one bike when button A is pressed.

He changed the code, he tested it again, so he went through the start simulation, and this time it worked.

So he's now happy to download that and try that on his micro:bit.

Check for understanding.

What does debugging mean?

So debugging a programme means to, A, find problems in code; B, solve problems in code; or C, find and solve problems in code.

Which do you think?

That's right, well done.

It's finding and solving problems in code.

That's correct, well done.

Right, we're now ready to connect the micro:bit to the computer so that we can start downloading it and using the micro:bit as a data logger.

So the first thing to do is to connect the micro:bit to a computer.

Now, usually micro:bits will come with a USB cable that fits into a USB-A slot within a computer.

Some computers you might need to have an adapter to be able to do that.

But the Micro-USB end of the data cable will fit into the top of the micro:bit.

Once that's plugged in, you should hopefully be able to see the micro:bit drive appear in your computer folders, and it's been there circled.

Third thing to do is now download the code, sorry, click the download code button in the Tinkercad.

So the programme that you've made will then start to be downloaded to the computer.

At the moment it's just in the cloud, it's not on your computer at all.

So we need to put it on the computer to then put it onto the micro:bit.

What you will find is that the micro:bit programme will actually appear in your computer downloads, and you can see it there.

It says oak_national_data_logger1.

hex.

If you're in any trouble trying to find the programme, it's normally always downloaded as a hex file.

The next stage is you then need to drag that over to the micro:bit and drag that file onto the micro:bit.

And what you'll notice is that actually the micro:bit LED starts flashing yellow, and when it's finished downloading, then it will stop flashing yellow and just go back to a normal yellow.

But that flashing means that actually something's happening and you definitely don't want to disconnect it 'cause not all of the programme will go down.

We then disconnect the micro:bit from the computer, add the battery pack, and then test the programme.

Now, obviously, you need to be very careful with the battery pack and the types of cells that you use, and that's something to discuss with your teacher to make sure that you're doing that carefully and safely.

You might also need to be really careful when you're adding that battery pack because, and I've had this from experience, is that actually once they're fitted, they fit in quite nice and easily, but actually disconnecting them can be an issue.

So if you do need to take the battery pack out for any reason, do be very careful and speak to your teacher, 'cause they are a bit fiddly and quite stiff to pull out.

Right, Task B.

I know it looks like a lot here, but they're quite simple instructions, okay?

So we'll go through them all again.

Again, you can always go back through the slides to go through the pictorial steps as well.

But let's go through them and reiterate what you've got to do.

So you're going to simulate and debug your programme.

So that's the first thing.

So you're not doing any downloading yet.

You're just gonna quickly test it and make sure it still works.

Then you connect the micro:bit to your computer.

Then you download the programme.

Then you disconnect the micro:bit.

Then you add a battery pack.

Then you add the cells to the battery pack, and then test the programme on the micro:bit and see if it works.

Now, if we've done all of the debugging, all of the programming, I'm sure it will work really well.

Now, this actually won't take very long.

There's seven instructions here, but it shouldn't take too long to do this.

Right, in which case, I'm gonna let you get on with it and I look forward to seeing you in a moment once you've got everything downloaded to your micro:bit.

Well done in advance.

Right, Aisha's programme was successfully downloaded to the micro:bit and it kept an account of the traffic.

Here we've got it working.

So you can see B's being pressed.

T has just been tipped over to the side, and you saw the T arrive.

So you can see that this is actually working.

And she was able to see her results.

So when she pressed A and B, then we had the results coming up with a number, and hopefully you've been able to have that too.

So if you haven't had a chance to see your results, then do go through and try and test and make sure that your results come up as well when you press A and B.

Right, well done.

Done really a huge amount today.

There's been quite a lot to learn and quite a lot of coding to do, but think about how much you've been able to cover in this lesson.

I think it's been really, really good work and you've done very, very well today.

So let's go through the summary.

Coding blocks are used in Tinkercad to create programmes.

A variable is a place to store data in a programme.

And programmes have to be downloaded onto a micro:bit.

So, thank you very much for being with me today.

You've done so much, you've done a really, really good job.

Very proud of what you've been able to achieve today, so you should be very pleased with yourselves as well, and I look forward to working with you next time.

Okay, thank you very much and goodbye.