Explorers Week 8 – Making a Start on a Paint Program

Hi everybody,

No notes this week, I will wait until we complete the game this Saturday.

Hope you all enjoyed the visit from Medtronic, we really appreciate the volunteers coming out to see us and showing us all the really interesting and exciting things they do….and the lollipops were lovely too.

See you all next week and we will complete our Painting program

Martha

 

Creators – Arrays and Classes

Several Values in One Place

This week we looked at two very useful concepts in JavaScript, Arrays (we’ve also called them lists) and Classes (we’ve also called them objects). They are both things that allow one variable to store more than one value at at time. This can often be very convenient and has the potential to save us a lot of typing! Who doesn’t like that?

Arrays

A plain variable in JavaScript can store a single value, we’ve seen that loads of times:

let a = 5;
let b = 7;
let c = a + b; // will be 5 + 7 = 12

An array variable in JavaScript can store more than one value, just by putting them in square brackets and separating them with commas:

let a = [5, 7]
let c = a[0] + a[1]; // This is the same as above!

The code here does the exactly the same thing as the block above it. See that a now has two values in it and we use a[0] to get the first value and a[1] to get the second. This technique isn’t super useful when we only have two values, but the more we have to store, the more useful this gets. Imagine if we had 10 values,  how much shorter would the array version be?

You can also create an empty array and put values in it later:

let a = [];
a.push(5);
a.push(7);

In the code above we create an empty array (nothing between the square brackets) and then use the push() function to add two values into it.

Concept of Classes

A class is a programming concept that lets you define objects which contain both Properties and Methods. Properties are values associated with the object. Methods are actions that we can ask the object to perform.

class

Think of yourself as a Person object and imagine some of the Properties and Methods you might have.

Your Properties might include NameAgeHeightWeight, etc. A simple Method you might have could be SayHi(). That would make you say “Hi, it’s <Name>!”.

A method might have arguments, so it could be SayHiTo(“Dave”) which would make you say “Hi Dave!”.

Classes in JavaScript

Making classes in JavaScript is pretty easy. Let’s look at the Person class we showed above:

class Person{
  constructor(name, age, height, weight){
   this.Name = name; 
   this.Age = age; 
   this.Height = height; 
   this.Weight = weight;
  }
  
  SayHi(){
    Console.Log("Hi, it's " + this.Name + "!");
  }

  SayHi(who){
     Console.Log("Hi " + who + "!" );
  }
}

We say “class“, the name of the class and a pair of curly brackets. Inside these brackets we have three functions (but notice we don’t have to say “function“).

Let’s look at the first of these, called constructor(). This is where we set the class properties. Note that we must put “this.” before properties to distinguish them.

The second two functions, SayHi() and SayHiTo() aren’t too usual, again note that we must use “this.Name” to get the value of the name property.

Download

This week we created a class to represent a bouncing ball and we saw how easy it was, once we’d created the class, to make several of them, all bouncing around simultaneously. This would have taken us a lot more code to do if we hadn’t made a class. As always, the files can be downloaded from our Github page.

 

 

 

 

 

 

Week 7 2017 – Explorers – Piano

Hello everyone,

Thank you all for coming again this week and I hope you enjoyed the Halloween break.

This week we did a simple Piano.

piano

We only had to draw two keys, and then could duplicate these and change the names. The same applied to the code. The code is the same for each key apart from one small change so the note is the appropriate for the key.

REMEMBER! You need to make four changes each time you duplicate:

Change the name of the spite to the next Note

Change the name of the TWO costumes

Change the NOTE played

Piano2

Piano3

 

Here are notes from this week in PDF CDA-S6-Week_07-Piano.pdf

Martha

Hackers – Project SABRE

ProjectSABRE

In the Hackers group, we started working on design of semi-autonomous or fully-autonomous battle-bots.

We are using the name “Project SABRE” as described in the graphic above.

Members of the group took first steps in learning how to control a robot by setting up a controllable circuit for LEDs.

This should be an interesting project to return to after the break!

DSC_2258

 

Bodgers – Making More Progress

This weekend in the Bodgers Group our three Raspberry Pi Pioneers teams continued to work on their projects.

The Zombie Herders were working on a PIR (passive Infra-red) sensor which is the type of sensor commonly found in burglar alarms.

IMG_20171022_141129

They used the GPIOZero library for Python and sample code which can be found here. However they didn’t have much success so we need to do more testing on our sensor and if necessary order a new one.

The zombie trolls worked on creating a 3-D model for their project using FreeCAD which they will print out when we return after the break.

stopper_3d

I’m afraid I not allowed to discuss what it will be used for at this point :-).

Team Green Fingers worked on more scripts for their project including using their Arduino and a relay to switch a 12 volt automobile bulb on and off.

flash

As with most projects like this we had a little trouble getting it going as we forgot to set the pin we used on the Arduino as an Output. Thanks to James and his Dad for bringing in the 12 volt powerpack.

We are off for the next two Saturdays and we’re back again on the 11th of November.

See you all then

Declan, Dave and Alaidh.

 

Explorers – Week 6 – Halloween Scene

Hi everyone,

Hope you enjoyed this weeks session and remember we are off for the mid-term and so our next session is on the 11th of November.

To get ready for the spooky season we created a Halloween Scene, lots of scary sounds and switching of costumes to create the effect of movement.

I chose a Witch with a wolf howl but I saw lots of great ideas as I was going around the room. Some had Ghouls, others Vampires, its was all pretty scary.

We also learnt a nice trick for giving the allusion of movement. We had a bat change both its size and Costume and it worked very well to give the effect of the bat flying towards us with the moon behind it.

Here are the notes in PDF from this weeks sessions CDA-S6-Week_06-Halloween

Also if you want the completed Scratch Code you can download it by going on to the Scratch.mit.edu website login to the CoderDojo Account (details are in the notes) and search for CDA_Martha_Week06.

Hope you have a great Halloween, be safe when you are out Trick or Treating but have lots of Fun!!

 

 

Hackers – More 3D Modelling

Slide1

This week in the Hackers group, rather than demonstrating how to use SketchUo, we showed some models that Kevin/Michael had built (see above), and the challenge was to recreate them. Some people got so far as to be able to print their models.

We also started some planning on an overall theme – more on that next time.

Explorers – Week 5 – Guessing Game

Hi everyone,

Well! didn’t we have a very studious bunch of Ninjas last week, all very focused on our new game. Last Saturday we did a slightly different game to usual., There was no movement, no sensing when something happened. It was a Maths Game, a guessing game where the computer picks a random number and we had to guess the number.

We had to first make sure that a random number was picked using an Operator. Previously we have used a Variable to store a Score or Lives, but this time it was storing the random number and our guesses. Leaving them on screen as we were testing allowed us to understand more about the variable and what it does…it also made the testing a little easier.

Depending how any guesses we were given we repeated our code that number of times. As well as having to make decisions, i.e If_then, we also had to do a comparison before making the decision, to determine whether the guess was correct, too low or too high.

5guesess

I hope you all enjoyed the difference this week and we are going try something else different next week. We  (You)  are going to create a Animated Halloween Scene. Get your Thinking Hats On!

Here are this weeks notes in PDF: CDA-S6-Week_05-GuessNumbers.pdf

Creators – Being Random

Screen Shot 2017-10-17 at 00.56.49

This week we mainly looked at three things:

  • How data is organised on your computer
  • Creating functions
  • Using randomness to make things interesting

Data Organisation

Most of us had heard of a hard-disk before. This is a stack of metal disks inside your computer. Each metal disk has a special coating made of millions of tiny magnets (like you might find stuck to the fridge) that can be turned on and off.11644419853_9499fa0faa_b

We saw that able to turn something on and off, like a switch, was enough to count from zero to one, but the more switches we added, the higher we could count. Two switches can count from zero to three:

Switch 1          | Switch 2          | Total (Add)
[Off = 0, On = 1] | [Off = 0, On = 2] |
------------------+-------------------+-----------
Off = 0           | Off = 0           | 0
On  = 1           | Off = 0           | 1
Off = 0           | On  = 2           | 2
On  = 1           | On  = 2           | 3

With enough of these tiny switches, we can store anything we need. Each of these tiny switches is also known as a ‘bit’ and a 1 terabyte hard disk has a billion of them!

We also saw that the files on your disk are arranged with folders (also known as directories). Folders can contain both files and more folders. This allow us to keep our hard disk organised; without them all our files would be in the same place which would be difficult once we had more than a few. The location of a file is called its “path”. Looking at the highlighted file on the desktop of my Mac we can see the full path would be:

Screen Shot 2017-10-16 at 22.19.59

/Users/kierancoughlan/Desktop/Ball and Bat Sounds.m4a

 

This means that, reading backwards, the file called ‘Bat and Ball Sounds.m4a’ is in a folder called ‘Desktop’ which is itself inside a folder called ‘kierancoughlan’ which is, at the highest level, inside a folder called ‘Users’.

Functions

A function is a collection of commands that do a job together. We’ve already encountered them, even if you hadn’t especially noticed:

  • Our P5 template already contains two functions called start() and draw()
  • All of the P5 commands we have used, such as createCanvas() and rect() are functions themselves

We could add all our code to start() and draw(), in fact, that’s what we’ve done before this week. That’s fine starting out, but it does mean, once there are a lot of commands in those functions, that our code is gets harder to read and understand. Breaking out a few commands into a new function and giving it a name that describes what it is doing, really helps.

Once we’ve written a function, it can be called as many times, and from as many places, we as need.

Functions can do one other thing too: they can give back a value to the place where they were called from. For this we use the special word return. For example, let’s see what a function to pick the largest of two numbers, we’ll call it Max(), might look like:

function start(){
    let a = 4;
    let b = 10;
    let c = Max(a, b);
}

function Max(n1, n2){
    if (n1 > n2)
        return n1;
    else
        return n2;
}

We give Max() the two numbers we are comparing. If the first one is bigger than the second, it gives back the first. Otherwise, if gives back the second. Note too that the names of the variables in Max() are different to those in start(), and that’s not a problem.

Random

Finally, we looked at the P5 function random(). We used it two different ways:

random(); // gives a number between 0...1
random(n); // gives a number between 0...n (where n is a number!)

In the first form, we used it to pick a random colour. In the second, we used it to pick a random position for our squares.

Files

As usual, all the code is on the creators github repository. Head there and download it!! The files for this week contain both the script we wrote (sketch.js) and a longer version that I wrote (sketch2.js). Feel free to take a look at both!