Category Archives: Schools

Using a FUNCTION in Scratch

A function is basically a series of steps that you teach the computer – it then learns the steps and can use them when you ‘call it’. The idea is you don’t need to continually tell the computer how to do something as it already knows.

In this case, we are going to teach the computer how to work out the percentage of a number.  The steps are:

  1. Take the number and divide it by 100
  2. Multiply that answer by the percentage you want
  3. Print out that answer

In Scratch, you can do this using the MAKE BLOCK function. You define the block and put in how many numbers you need. In the function, you define the steps and return the answer.

You then ‘call the function’ by adding the block to the code.

function

Easter workshop fun

What a  great start to the Easter. Sold out sessions and lots of children keen to do coding and physical electronics.

Just some examples of what’s been happening.

sonic

These are some children coding music with Sonic Pi. It seems that knowing your Grade 1 piano pieces helps with inspiring your composition.

joystikcs

And a packed out session of children learning to code joystick games using the Arduino. Some very inventive ideas.

We used neopixels to create some bright lights.

neo1

And of course, we did Minecraft

minecraft1

 

Robots and algorithms at Stockton on the Forest

Great day at Stockton on the Forest primary. Started the day with an algorithm assembly.

How would you sort 10 children by height? We did a bubble sort algorithm – followed by using an algorithm to find a number a child had thought of.

Then a fun day coding robots. The children wrote text codes using Arduino to make their robots perform sequences. Then we demonstrated them at the end of the day in assembly.

A search algorithm you can act out in primary school

Imagine you’ve got100 children all lined up. You want to know if someone is called Sarah and what position they are.

There’s a few ways you can do this – what you can’t do is ask anyone.

1)Get them in a line. Ask each child their name.

IF Name = Sarah, then check position and say that Sarah is at that position. Keep going until you reach the end.

OR

2) Sort the children into alphabetical order (IMPORTANT)

Find the middle child. IF their name is before Sarah, then get rid of the first half. Or the second half if after Sarah.

Then find the middle child again. Repeat the process as above.

By halving, you will find the Sarah.

This can be adapted into a guessing game.

Imagine a number between 0 – 100. Computer guess 50. If Higher, guesses 75 etc.

Worked example.

Number is 57

Guess 50 (HIGHER) Range left 51 – 100

Guess 75 (LOWER) Range left 51 – 74

Guess 63 (LOWER) Range left 51 – 62

Guess 56 (HIGHER) Range left 57 – 62

Guess 59 (LOWER) Range left  57 – 59

Guess 58 (LOWER) Range left 57 – 57

Guess 57. CORRECT

This is called a DIVIDE and CONQUER algorithm. It’s designed to cut down the work. An alternative could be to go through from 0 – 100 and get the answer HIGHER or LOWER. It would work but it would be slow.

You could do RANDOM guesses.

Teaching variables using Sonic Pi in primary classroom coding

Variables are very powerful. They are used in Scratch and can easily be taught through drama.

VARIABLE Life = 5

VARIABLE Points = 0

VARIABLE Game Over = false

IF you get touched, you lose a life

IF you score, you get 1 point

FOREVER (if GAME OVER NOT TRUE) CHECK LIFE & POINTS

IF LIFE = 0, GAME OVER = TRUE, WIN = FALSE

IF POINTS = 10, GAME OVER = TRUE,WIN = TRUE

IF GAME OVER = TRUE, CHECK WIN.

This demonstrates how variables can be used in music using Sonic Pi.

The power of variables – making music easy in KS2 coding

Variables are really useful – as the name suggests, they can vary. When you make a simple change in the variable, the result can feed through a program rather than you having to type it in everywhere.

So for music, we have developed a function. In functions, you can “send” details to a function and it will carry it out for you. It saves you having to keep typing the function again and again.

Continue reading