video

Lesson video

In progress...

Loading...

Hello, my name's Ben, and welcome to the final lesson of this programming unit, all about sensing.

In this lesson, you'll be making a micro:bit based step counter.

You'll need a pen and a piece of paper.

You'll need somewhere quiet, away from distractions.

And for later in the lesson, it might be useful if you've got some basic arts and crafts materials, things like Sellotape or Blu Tack, just to help with the final project.

When you're ready, we'll begin.

We'll begin by looking at the objectives for this lesson.

The overall objective is that you're going to develop a programme which uses inputs and outputs on a controllable device.

You're going to create a programme based on a design.

You're going to test a programme against a design and use a range of approaches to find and fix bugs.

In this lesson, you're going to create a programme which is based on a design.

You can use the design you created in the previous lesson, or if you don't have that design or you didn't complete the previous lesson, you can use the example which is provided in the worksheet.

Whichever design you're using, this is your last chance to review your design before you make your programme.

So for the last time, check, is the design clear enough? Do you know what you need to do? If you need to, make any changes now.

This is your opportunity to bring everything together into your last project.

You are now going to create your code based on the design you have.

To help you along, we've provided a template project with some of the blocks you will need.

Make sure your project really reflects your design.

So make sure it includes the variables you've added in your design.

Make sure the appearance of the project is as you've designed it, so the text and the numbers that you will display on the micro:bit.

Make sure that the algorithm is represented in your blocks and that the programme flow is followed.

One last tip before you create your code: remember, when you add your code, to test, test, and then test again.

As you create the code, just keep testing it.

Each time you add a new block, test the code.

Do this using the emulator.

It will really help you to debug your code more easily.

Have fun making your project and good luck.

Debugging is the process of finding and fixing errors in your code.

If you find there's mistakes in your project or it's not functioning as you would expect, then you need to go through the process of debugging.

Here are two approaches you can use when debugging.

On the left, we have isolating code.

This is when you take a section of code out and test it on its own.

So in this code snippet, the if is shake gesture then block is highlighted and we're going to take that out and put it in its own forever loop, so we can test it on its own.

We can then find if there's any issues with that particular piece of code.

If there isn't, we can drop it back in and then test the next bit.

Another method you could use is the substitute code method.

This involves swapping a section of code and testing it again.

So this time, again, we're going to take a piece of code out, but we're going to swap it back in with a different piece of code.

So the swap we're doing below is set step to change step to see if that solves the problem with our code.

Go back to your project and debug it.

If after debugging, you're still having problems with your code, then you may want to have a look at a possible solution for this project.

Compare this to the code you have created and see if you can spot where you may have made mistakes or where there may be some errors in your design.

Pause the video to complete this task.

You've now created your code from a design, tested it in the emulator, debugged it, and compared it to a complete example.

Now, if you have a micro:bit itself, you can test it as a step counter.

You'll need to flash the programme to your micro:bit.

Then what you'll need to do is, in some way, attach your micro:bit to your foot or to a shoe so that it can work as a step counter.

This is one way you could do it.

Tuck the battery pack into the side of your shoe, thread the wires into your laces or buckle, and then connect your micro:bit using the battery pack.

If you need to, you could use sticky tape or an adhesive putty to secure your micro:bit if it is too loose.

Have a think about how you might secure your micro:bit to your foot or to your shoe.

Pause the video and resume once you're ready.

You may have noticed that when you shake your micro:bit or shake it within the emulator, the variable step changes by more than one.

To fix this, we can adjust the sensitivity of your counter.

To do this, you need a different block.

So instead of the on shake block, you need the acceleration strength block, which you can see on the diagram below.

We've provided you with a project where this block is included.

Have a go at changing the number in the pink circle.

See if you can adjust the sensitivity so that each time you shake your counter, the variable step changes by one.

When you've made your changes, what do you think you need to do? You guessed it, test it again.

Are there any differences in the functioning of your programme between the physical device and the emulator? Do you need to change the value of the strength block on the physical device and on the emulator to make it work as a step counter? Keep testing and keep trying until you come up with something that works for you.

Congratulations, you've reached the end of this programming unit on sensing.

I hope you've enjoyed using the micro:bit or using the emulator and creating all the projects we went through in this unit.

There are loads of other projects online, which you can use with the micro:bit.

It's amazing what you can achieve.

Don't let the learning stop here, have a go for yourself.

We'd love to see the work you created in this unit, so share your work with Oak National.

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

Thank you.