video

Lesson video

In progress...

Loading...

Hi, I'm Allen, your computing teacher for this unit on physical computing.

And this is lesson two of six.

In this lesson, we're going to be looking at the individual LEDs on the micro bit, and locating how we can light up each individual one on their own without displaying messages or pictures as a whole.

But looking at lighting individual LEDs.

You will need your microbit obviously for this lesson and a USB cable to connect it to your computer.

You can turn off all notifications because we don't want to be disturbed while we're doing this cool stuff.

When you're ready, we can make a start.

Okay, in this lesson we're going to continue using the five by five LED matrix on the microbit display some information.

You'll know from last lesson that we could display some images.

And just to recap on that one, I've got a little test for you to begin with.

You're going to show some images a bit like you did last time.

But this time you are going to use a for loop to iterate through different images rather than just having one.

So there is a worksheet for this task.

All explained on there as far as the code you need, and what you need to complete.

You can pause the video and get started.

Okay, so here's one possible solution.

We've seen the faces from the from lesson one, so you got the smiley face at first.

And then we've got an umbrella here.

And then we have a ghost.

So the code would look a little bit like this.

So I replaced the gaps, I filled the gaps in with the words happy, umbrella and ghost.

And as it said in the work, there's lots and lots of images you can look for to display on the micro bit, there are just three of them.

For the loop, we've iterated through the list.

So in that list of the happy face and umbrella and a ghost, we've said for image in images.

So for every image in that list, display the image, okay.

And I've replaced in the brackets, I've put the word image there.

So, that's going to go through each image in the list.

It will go through it once, display the image and then it would stop.

But if you just want to leave it on, on the last image, then that would be fine.

If you wanted it to clear at the end, then we'd use display dot clear.

And that would clear the display ready for if you want to run it again.

So Python is case sensitive.

Uppercase and lowercase characters are different.

So you've had an issue there, maybe that might be something to look for, if it didn't work.

And what I would encourage you to do is if you didn't get it working, put some of this code in and give it a go and give it a try.

So you're at least successful with getting an iteration of some images going through using a loop.

Because it's really important that rather than leaving something unfinished, they actually give it a go and you can have some success with the images.

Okay, let's move on.

I think there right in the very beginning, when we did the introduction that in this lesson, we're going to concentrate on controlling individual LEDs, okay.

So when we have the happy face or the sad face or the umbrella, then the microbit takes that and interpret certainly knows which LEDs to display or to light up.

But we can control them individually.

So if you look at the diagram on the screen, you can see x and y coordinates.

And they relate to the positions of the LEDs on the microbit.

So for instance, if I wanted to light up that top left hand corner LED, then the code for that would be display dot set underscore pixel.

And then in brackets I've got x, y, and value.

So x is along the top as the x axis, so that's the column number.

And then the Y is the row number.

So for the one in the very top left, you can see it would be zero comma zero.

The value variable at the end, that's just how bright you want it to be, okay.

So this ranges from naught which would be off, which would be no point, doing the line of code or so you probably start at the lowest, which would be one all the way up to nine.

So nine is the brightest it will go, go.

So I've got a task for you now.

So complete the programme below to light up the top right pixel.

So going on that example, you probably be able to see straight away what the variables may be.

You've got the four lines of code there, there is a worksheet for you to fill in to do this, other worksheet for you to follow to do this task.

And then there are some other tasks that follow on from it using what you've learned during the first part of the task, okay.

So you can pause the video and see how you get along.

Okay, hope you got that working.

You can see on the little animation there what it should look like.

You get one going one after the other.

And in the last part of the task here to put it all within a while loop to keep it going pretty much forever as mine is there.

So one after the other, each corner is lighting up.

You can see from the variables on the screen, the individual rows and column values that have been put in there so that you can see those lighting at one after the other.

Another way of doing this would be to use a kind of a list and indicate in that list which LEDs are to be turned on, and to what level of brightness.

So here in the example, you can see we've got corners equals image.

And then within that image, we've got a reference for each individual LED within each row, and the number of the brightness for that LED, or what brightness that LED should be, okay.

And if you want to make it even more compact, what you could do is you could do the line of code right at the very bottom there.

So you just have it all on one row.

Visually, personally I like the one above, because you can kind of see how though, how it might be displayed and you can recognise which ones might need to be switched on or off, and you can kind of see it before you even run it.

So can you see the relationship between those numbers and the LEDs? Well, hopefully can.

If we look at the picture, on the right hand side, all four corners are lit up again.

And they're quite bright or they're very bright, they're as bright as they'll go.

And we can see from the code on the left, the ones in the individual corners of that kind of text representation of the LEDs, they're nine so that it's as bright as they'll go.

And equally, you know, we could put any of those other zeros to numerical values between naught and nine, and that would show or not show the LED different brightnesses.

Okay, so we've got task three for you now.

What values will be required to produce the star on the image on the right hand side? So you can see that star image.

The LEDs have got varying brightnesses now.

So you might have to experiment with this.

And you can see the code on the left hand side is got bunch of question marks in, you're going to see if you can replicate that picture on the right hand side.

Now we'll say, the four corners, this time, we're all off.

So you can pretty safely say that all four corners are going to be zero.

Okay, so that's a little tip for you.

And then as you go through, you'll have a look and see what values you think will go into make a star.

Okay, so there is a worksheet for this, you can pause the video, and hope you enjoy this task.

Okay, how did you get along trying to replicate the star? Well, the tip here as I said, when I gave you the introduction to this task was the four corners are all off.

So they would all obviously be zero.

And then if you're looking see that the brightest one is the very centre LED.

So that was the brightest we can have with nine, isn't it? Yeah.

So that one would actually be nine, and the four kind of around it above below, to the left and to the right, they're bright, but they're not as bright.

So in this instance, on my example, I've got them as seven.

And then the ones at the corners of those as fives.

And then as it dissipates outwards, the numbers gradually go down.

So I've got some threes in there as well.

So that would make that star so you can have some fun, not just making your own images, but you can make your own images with differing levels of brightness as well.

Okay, so hope you're enjoying this.

It's lots of fun coding LEDs and making them very bright sparkle and twinkle and what have you.

In this one we're going to sparkle some LEDs randomly.

Okay, so we're going to use randint which basically generates a random number.

So the different line of code in this one is from random, import randint.

So this is a random module, just like the microbit module.

But we only want rand integer random whole number from this.

So we're not putting a star, we're just saying, actually, from the random module, we only want to deal with randint.

So we're making two variables, one called x one called y, and we're making a random number between what? So that's the bit you're going to have to figure out.

So as far as the x and y values, they're going to be a random number but between what.

We're also making a brightness variable, and we're making that a random number, what will the two variables been there, the start and the finish.

So you have to think about that.

And then it will display those x, y and brightness variables in a loop while true, if user already in this lesson.

So you can complete the task and see how you get along.

Okay, so this was your task to complete the programme to set random pixels to a random brightness level, and create a sparkling effect.

So you can see the boxes have been filled in in this example now and I've gone for naught and four on both the x and y because if you remember the column was between naught and four, as was the row number, and then brightness between naught and nine.

So naught would be off as we know from previously and nine would be the brightest those LEDs can go.

And then we display the individual LEDs to that in that row and in that column to that brightness.

We just keep going round around around around doing that.

So if you've done that you should see a really rapid sparkle of LEDs on your microbit.

If you'd like to share your work with Oak National, please ask your parent or carer to share your work on Instagram, Facebook or Twitter, tagging @OakNational and #learnwithOak.

I'll see you next time time time.