Creators: Objects and Vectors!

This week in Creators we covered a few very important concepts which we will likely need to run over a few times until we get them solid!

What are Vectors?

First we looked into a concept called Vectors, in particular 2D Vectors.  We saw that at the most basic, a Vector is a simple way of holding an x and a y in one variable.  This is useful for keeping track of the position of an object as you only need to keep one variable e.g. “rocketPosition” rather than two “rocket_x, rocket_y”.

vector-add3

The other thing we talked about is how this X and Y can represent a change in a given direction – i.e. a vector with x=10 and y=5 can mean “change X by 10 and y by 5”.  This way it’s useful for ANYTHING that might be in a given direction – things like velocity and acceleration for example!

The other thing cool about the vector object in p5 is that it has a bunch of functions that allow you to add, subtract, etc them.  This would allow you to e.g. add a velocity vector to a position vector to come up with a new position vector!

This web page has some nice details on the maths behind vectors.

 

Position, Velocity and Acceleration

We saw that position, velocity and acceleration are really common uses of vectors.

Continue reading

Bouncing around in Javascript

This week we looked at animations, and how to make objects move in p5.js.

We covered:

  • How to animate things in p5
  • Some mouse interaction

Animation in javascript (or all programming really!) is basically changing some variables in the draw function before we actually draw the object.  If we change each variable by a little bit, it looks like smooth movements, just like a cartoon!

To save some typing, there is a video below with a quick overview of what we did:

Okay, it’s pretty simple stuff and not exactly the most exciting animation in the world, but you guys did some playing around and came up with several interesting variations and now we know how to do it, the sky is the absolute limit on what we can build  🙂 !

As usual, the code is up on the github to be pulled down and played with or changed to your heart’s content!

 

Explorers Week 5 – Help Bo Peep find her sheep

Hi everyone,

Thanks for coming Saturday even though the weather was dreadful.

This week, I helped Bo Peep found her sheep! Some of you did the same and some used ideas like Minecraft Steve finding Iron Ore and Diamonds, Knights finding dragons or a Princess finding flowers.

Before we even started our game this week we talked a little bit about File Management and about the importance of keeping your files somewhere you can access them quickly and giving them a meaningful name.

So to this end, we all created a folder where we will be keeping our files in the future and within that we had a sub folder for this weeks files.

We started our game by drawing our background on our stage:

Unfortunately, due to internet problems we could not search the internet for images for our Sprites, but we could still use the sprites from the Scratch Library.

This week, we decided to move our main sprite using the arrow keys. For this we had to learn a small bit about the X and Y axis and I gave you a little tip on how to remember which is which!

Hope you all enjoyed this week, aee you next week when we will be starting a new game!

Here are the notes for this weeks session in PDF CDA-S7-Week_05-BoBeep.pdf

Martha

Julie, Ruaidhrí and Eoin

 

Hackers – Temperature Control, Part 2

Today we continued towards building a temperature controller.

Last week, we used an LM35 temperature sensor to read the temperature in the room and report it on the Arduino serial console.
We were able to get a reading for the temperature of the air in the room, and the temperature of a cup of coffee touching the sensor.  We couldn’t be sure, however, that the readings were correct.  So, we decided to test with a potentiometer and a voltmeter.

We supplied 5 V to the potentiometer and fed the output to the Arduino.  We used a voltmeter to measure the output from the pot and compared it to the reading from
the Arduino.  Once we got the code working, we got good agreement on voltage readings between the meter and the Arduino.

The sensor presents a voltage on its output pin that represents the temperature its measuring.  In its basic mode, the sensor reads temperatures between 0.2 and 150 degrees Celsius.  Every degree is 10 mV, so the output voltage ranges from 2 mV to 1500 mV.  Converting our voltage reading to a temperature is simple then:  divide the voltage reading in millivolts by 10.

We can use one of the analog I/O pins on the Arduino to read the voltage.  The analogRead() function returns a value between 0 and 1023 for voltages between 0 and 5 V.

We digressed into how to use a multimeter correctly.  The first thing to do is make sure that our meter is set up correctly.
We tried measuring a 9 V DC battery with the DC voltage setting and got 9.2 V.  We then tried measuring the same battery with the AC voltage setting.  This time we got 19.6 V.
There’s a lot of potential (sorry) to get confused, then.  Worse again, if we try measuring 220 VAC with the meter set to DC, we get a reading close to zero.  In other words, a live AC supply looks safe if we set our meter wrong.

Next, we start with the highest reading range and step down.  For a 1.5 V battery, we start with the 200 V reading, then step down to 20 V.  This is to protect the meter:  if the voltage is higher than we expected, we might damage the meter.

Voltage readings are taken in parallel with the circuit, and while it is live.

Resistance and continuity readings, on the other hand, are taken with the component disconnected from the circuit.
We worked out why with a simple circuit:

circuit1

F is a fuse.  W is a wire between the two ends.  We’re not sure if the fuse is blown.  We try testing for continuity across the fuse by putting our meter leads on A and B.
Even if the fuse is blown, we will get continuity because W provides a circuit.  We need to cut the wire to get a true reading.

Our first attempt at Arduino code for the voltage reading gave us a surprise.  Our meter displayed 2.5 V.  The Arduino displayed 2 V.  We used this formula to calculate the voltage:
v = 5 * analogRead_reading / 1023.
V was declared as float variable.  analogRead_reading was declared as an int.  The Arduino code multiplied two ints and divided the result by another int, truncated the result and stored the int as a float.  When we made the 5 and 1023 floating point numbers (5.0 and 1023.0), we got the right answer.

Once we were happy with the Arduino code, we replaced the potentiometer with an LM35.  Unfortunately, we didn’t notice the “bottom view” label on the datasheet drawing.  We connected the 5 V supply to the wrong side of the sensor.  It’s amazing how hot a temperature sensor can get!  It was too hot to touch.  And we couldn’t measure the temperature because…
After we disconnected the LM35, we made another discovery:  we continued to get random voltage readings displayed on the Arduino even though there was no voltage to read.  The analogRead() function happily outputs values from random noise.

Next week, we’ll use an LM35 connected the right way around, and try controlling a relay to switch power on and off to an external device.  We’ll build a temperature controlled soldering station carefully – we want to solder with the tip of the iron, not the temperature sensor.

Creators: Creative Coding with p5.js

What is P5?

This week we looked at p5.js – a library to make creative coding in javascript MUCH easier!  We first downloaded and copied p5.js onto our computers, and copied it into a new project folder.  We included p5.js in a html file, just like we included our own javascript file last week.

In fact, we looked at the file and realised that p5 is just another javascript file, just like the one we wrote – the code is long and looked a bit complicated, but it was basically the same kind of thing.

 

But really, what is P5?

p5 is a set of functions that make it easy to write programs for the most interesting parts of javascript!  Mainly, for drawing and animating things on a webpage, but also for sound, and other stuff.  If has lots of functions for:

Continue reading

Bodgers – Making For The International Space Station

Hello again everybody.
This week in the Bodgers group we started working on our code for the Mission Zero Challenge.

mission-zero-logo

We began by writing a simple text message on the 8×8 full-colour LED display, then we changed the text and background colours. We then coded a picture by assigning a colour to each of the 64 LEDs on the display. We finished the session by taking a quick look at using the temperature sensor to read the temperature. Here are my slides from this week day 2.
Next week we will recap what we covered this week and we will start to personalise our code for the challenge.

In the meantime, here’s a couple of fun videos on how the Astro Pi computers got to the ISS.

See you all next Saturday

Declan, Dave and Alaidh

Advancers – Piano

Welcome to all the new Advancers.

For our first week we built a Piano, which you could play manually or record a tune and then play it back.

We started with a basic plan:

  • 1 Piano Sprite
  • 3 Button Sprites
    • Record
    • Stop
    • Play
  • A list to store all the possible Piano notes.
  • A list to store the tune being played.

Luckily Scratch comes with a Piano Sprite, which we used and expanded it to fill the width of the screen.

PianoSprite

Next step was to create the list of all the notes, there are 14 keys on the Piano so we need at least 14 notes in our list.

We found out what notes are possible by using one of the Sound blocks and looking at what was possible

PossibleNotes

This gave us our list of possible notes:

NotesList

Now on to the code…

We needed to work out what key on the Piano had been clicked, and convert it to a number between 1 and 14 so we could play the correct note from the list.

This required some tricky calculations, to convert the Mouses “X” position to a positive integer between 1 and 14.

  • First we added a number to make X always positive
  • Second we divided that by the size of a note.
  • And finally we rounded it up, using the ceiling function.

This ended up with the following code and a couple of Variables to store the “Extra” number to make X positive and the size of a note:

NoteClickedBasic

Once we had the positive integer we could use it to select the correct note to play from the list:

NoteClickedMedium

We did start some of the Buttons, and we will complete them next week. Notes for the buttons will be included then.

Buttons

In order to make the Piano a bit more usable we added 3 Buttons:

  1. Record
  2. Stop
  3. Play

All three Buttons had two costumes, we used the second costume to change the colour of the Button, this made it easy to see if you had clicked the button or not.

The Record button, simply set a Data Flag to indicate to the Piano code that it should “record” the notes being played in a List variable.

It also flashed while recording was “on”, this is the code for the Record Button:

RecordButtonCode

We also had to add some additional code to the Piano to make sure the notes were recorded:

RecordPianoCode

The Stop button was quite simple, we just set the Data Flag back to 0, and changed the costume for a short while to make it clear that the button had been pressed.

StopButtonCode

The Play button was a little more complex as it need to read all the items in the List and play the correct notes. It also flashed while playing. This is the code from the Play button:

PlayButtonCode

The Final project looked something like this, you can get a copy from the Scratch Web Site, see the Notes below.

PianoStage

Notes:

Note: My version of the project has been uploaded to https://scratch.mit.edu you can Sign in using the following details:

  • Username : cdadvancers1819
  • Password : advancers
  • Project Name is : Class-Piano

CoderDojo Athenry Returns on 15 September 2018!

cdathenry-returning

CoderDojo Athenry is starting back with an information session on 15 September 2018 in Clarin College Athenry (“the Tech”) at 12:00 noon. All new and existing members are welcome to come along to find out what we have planned for this season.

Regular weekly sessions will start the following week, 22 September 2018, 12-2pm in the same venue.

New members are always welcome. If you are aged between 7 and 17, just come along on the first day and fill out a registration form. Young people aged 12 and under have to be accompanied by a parent/guardian for the whole session.

And don’t forget, CoderDojo Athenry is run by volunteers and is completely free for participants — no membership fees, no weekly contributions. You should bring a laptop if you have one, but we have some loaner laptops if you don’t. There is more information on our About page.

We hope you can join us. You are welcome to invite your friends along too!

Bodgers – Coolest Projects UK

As you may remember from before Christmas Kevin, Zack and Barry won a prize in the Raspberry Pi Pioneers competition, part of that prize was an invitation to Coolest Projects UK which was held in London last Saturday.IMG_20180428_130215

The first thing that struck us when we got there was how small the event was, there was about forty projects there, compared to Coolest Projects in the RDS. However this is the first time that Coolest Projects has been run in the UK so it’s a very good start. We also noticed that at least half the projects were hardware based which reflects the fact that there are more Raspberry Jams etc. than CoderDojos in the UK.

The day started with us setting up our “Piggy In The Middle” project, followed by a very nice speech by Philip Colligan. The lads then demoed their project to the public while they were waiting for the Judges. After the judging was finished there were science shows by Greg Foot and Neil Monteiro as well as stands to keep the kids entertained, Zack and Kevin really enjoyed the huge version of Connect 4 that was there. In what has now become Coolest Projects tradition for Kevin and Zack they had their picture taken again with Philip Colligan CEO of the Raspberry Pi Foundation.

Db3elddWAAA30cE

Then it was time for the results, the Mobile category award went to Meriem Ait Ziane for her app of healthy eating recipes and advice as well as support for diabetic people and a personalized diet plan according to your health conditions.

The Games category was won by Hamdan Syed and Amiyan Ezdi. The game they coded is called Calorie Challenge, which challenges you to remember the amount of calories in each meal/snack.

The Website award went to George Hart for his project called “Educelevate”. He designed the website to educate children of all ages on various topics.

The Scratch category was won by to Gabriella Jenkins and Liya John for their game “Toad Ahoy”.

The Hardware category went to Avye Couloute for her project: Voice O’tronik Bot. We were all very impressed by both Avye and her project and were delighted to see her win.

We enjoyed our visit to Coolest Projects UK and we can’t wait for Coolest Projects in the RDS.

Back in Athenry Dave helped the rest of the Bodgers with their projects.

Creators Quiz Time

This week at Creators we took some time out to play some games and do some quizzes – well done to everyone that took part!  We used the fantastic website “Kahoot!” to drive the quizzes.  Some of you had used this site before in school.  We had a little trouble getting it going due to network trouble, etc but got it sorted and interestingly saw how we could debug the issues in the kahoot javascript using the console to see that it was the network causing the problems, just like we did with our own code.

Anyhow the results of the quiz are below – everyone did brilliantly as expected but LORD PJO showed her quickfire dominance by amazingly winning two of the three games:

We then did a rapid-fire challenge to do a circle that changes color when the mouse is over it.  This is one of those ones that is easy in scratch (“touching mouse”) but we hadn’t covered collision detection really in javascript so you had to figure it out.  Most all of you got it, some with really clever solutions!  My pretty simplistic solution is checked up to github as usual.

Next week we have a break and then we plan to spend a week working on our own ideas – anything you like – either bring in a project that you are working on and Kieran and I will try to give advice or just start a new one in the class and we’ll try to get you off on a good footing.