Saturday 4th November 2017

We would like to begin this morning’s session by first thanking Mr. Niall McKeever of Airporter Ltd. for his kind generosity in sponsoring 10 microbits and accessories of buzzers and neopixel led lights for the microbits bits for use at Derry Coderdojo.

We greatly appreciate his help!

Next, as I’m sure you are all aware, Children In Need is just around the corner! To get into the spirit of things we are taking part in Pudsey’s duck race. We have a list of 20 very funky ducks who will be taking part in a BBC Duck Race on Friday 17 November. You can sponsor a duck for £2. On Friday 17 November at 1pm, the Children In Need Facebook page will broadcast the race.

The person with the winning duck will receive a prize of £10 and the remainder of the money raised will be donated to Children In Need. If you would like to take part, just let Orla know. She will have the sponsor sheet to choose your lucky duck and the donation box also.

Today’s activities are all about learning how to control the LEDs on the Micro:Bits. There are quite a few tasks here so don’t worry if you don’t get it finished, we can continue at the next session.

Grids

For our first activity today, we need to review what a grid is.

Grids are a type of diagram that can be used to represent the position of something. e.g. on a map.

A coordinate grid is the layout of a group of parallel horizontal and vertical lines that cross each other at 90 degrees and the points at which they cross are called coordinate points.

For our ninjas who are used to working with Scratch, you will be familiar with their grid structure. The centre of your Stage is Scratch is at co-ordinate (0,0). The edges of the Stage are at -180 and 180 as shown in the diagram to the left.

The lines are known as the axis and are labelled X and Y. A useful way to remember this is “X is a cross and Y’s (wise) up”

Micro:Bit LEDs

As you know, our Microbits have a set of red lights on the front of them. These are called LEDs. We have already used these lights to show numbers, text and even some images, however today we are going to learn how to control each light individually.

When coding your Microbit, each light has its own name which is its co-ordinate. The diagram below shows the co-ordinates of every LED light on the Microbit.

Activity 1 – Battleships

Before we do any coding today, we are going to play a game called Battleships. Find a partner to play in groups of 2.

Now each player has to draw a grid which has 5 rows and 5 columns. It should be labelled to look like the grid below:

Now you need to draw three battleships on your grid. Don’t let the other player see where they are!! Your 3 ships should be 3 different sizes – 1 should be only the size of 1 square, one should be 1 square wide and 2 squares long and the last one should be one square wide and 3 squares long. Your grid should now look something like this but with your ships in different places.

The next step is to actually play! Player 1 goes first and circles one of the squares on their grid. They call out the co-ordinate of this square.

For example if they drew on the first square, they would call out (0,0)

Player 2 now has to look at their grid at (0,0) and see if they have a ship in it. If they do, they call “HIT” and draw an X on it. Player 1 gets a point and can take another turn. If their square is blank, they call “MISS” and it is now their turn. If your ship is covered in X’s (1 x for your smallest ship, 2 for the middle one, 3 for the largest) your ship will sink and you must tell the other player. Once all your ships have been sunk, you are out of the game. The winner will be the other player.

Activity 2 – Controlling Micro:Bit LEDs

For our next activity, we are going to code the Micro:Bits to display different patterns by controlling each individual LED.

Activity 3 – Random Pattern Generator

The first script (when A pressed) clears your lights and then randomly chooses 4 LEDs to switch on. The second script (when B pressed) code checks if an led (0,0) is on/off .

Try changing the second script to check a different coordinate or select a random LED instead.

Activity 4 – Code your own

Can you code your Micro:Bit to show the letters C when Button A is pressed, O when Button B is pressed, D when A+B is pressed and E when the Micro:Bit is shaken?

Activity 5 – Screen savers

There are loads of different shapes you can make now that you can control LEDs individually. Why not try out some of these examples?

Fireworks

Diamond

Try experimenting with some of the values to see how the patterns change.

Functions

As you all know, computer programs are a set of instructions that tell a computer what to do. Instructions can get very long and complicated. If we had to give instructions to each other the way we need to tell a computer,we would never get anything done!

For example, an instruction your mum might give you is “Please go to the shop and get a pint of milk for me.” That is probably all you would need to know. But if your mum was to tell a computer this she would have to say “Walk to the front door (and tell the computer where the door is) and walk to the shop (and give exact directions to the shop). Enter the shop (It needs to know how to open the door!) Get a pint of milk – it needs to know what is milk? Where will it find it? How will it pick it up? Go to the till (Where is the till?) Pay for the milk – how does it do this? etc. So you can see that very quickly computer programs can get very complicated. To deal with this, we use functions.

We create a function called GoToTheShop and code it with all the instructions needed for the computer to go to the shop. We can also create a function called GetMilk which has the instructions for finding the milk, PayForItems which has the instructions for how to pay and ComeHome which has the instructions for finding your house again.

This makes it simpler because now we can say to the computer – GoToTheShop, GetMilk, PayForItems, ComeHome.

This is much easier than listing out all the instructions individually every single time. We can also reuse the functions so maybe the next day our instructions could look like GoToTheShop, GetBread, PayForItems, ComeHome.

Activity 6 – Using Functions

In this activity, we are going to code our own functions.

The blocks needed for some of this activity can be found under Advanced and then choosing Make A Function