# Modellers – Game Controller Part 2 – Week 3

Hi folks, thanks again for another fun session today. We continued working on our game controller, moving the thumbsticks into place and creating a D-pad and template button. Here are my video notes:

Here’s a link to the folder where all our files. You’ll find a new file in there called controller_2.blend, containing everything we did this week.

# This week’s Challenge – To build a Calculator.

I know Windows has a Calculator, but we are going to build our own. This will give you an idea of how real Calculators actually work.

# The Calculator should be able to:

1. Add, Subtract, Multiply and Divide 2 numbers.

2. Be able to work with decimal points (2.5 for example).

3. Display the sum and the result on the screen.

4. Have a “clear” button to reset everything ready for the next calculation.

# Let’s look at the steps that you need for a calculation

1. Clear the variables.

2. Click on the numbers for the first number.

3. Click on the operator you want to use.

4. Click on the numbers for the second number.

5. Click on the equals button.

6. Display the result.

Hint: When you click on the Operator, this indicates we have got the first number and need to start storing the second number. See variable 6.

It sounds like there is a lot to do, but if we are smart with the way we work, there is a lot of code that is very similar and we can copy and paste it and then modify it slightly.

## You will need 6 variables (for all Sprites) to share:

1. The first number in the calculation (NumberOne), not visible.

2. The second number in the calcualtion (NumberTwo), not visible.

3. The complete sum (Question), visible.

4. The operator (+,-,x,/) for the calculation (Operator), not visible.

5. The result of the calculation (Result), visible.

6. A variable to indicate what number we are working with (SecondNumber). not visible.

Hint: When you press clear, all the variables should be set to blank, except the SecondNumber which should be 0

## You will need 17 Sprites, don’t panic! Remember copy and paste is your friend:

11 Number Sprites 0,1,2,3,4,5,6,7,8,9 and the decimal point.

4 Operator Sprite +,-,x and /.

1 Equals (=) Sprite.

1 Clear Sprite.

## Scratch code blocks that will be used:

Operators, we will use the join operator a lot as well as the +,-,x and /.

If Else block with variable 6 to decide what number to update.

set variable blocks – lots of these!

### Hint:

Start by creating the variables.

Start with just 4 Sprites, 1, +, clear and Equals

Once you can get 1 + 1 working, the rest is quite easy.

The answer is 2 (not 11) by the way, just in case.

### Coding Tips:

Here is some of the code that we will be using:

This is the code when you click on a number Sprite, this example is for the number 1, can you see what needs to change if this was the number 2 sprite?

This is the code for the + Sprite

And this is the code in the = Sprite

And finally, the CLR sprite

# Tips for CoderDojo Athenry Online Sessions

Using Teams

We are using Microsoft Teams. Each week, we will post links on the CoderDojo Athenry website and Facebook. Here is are the links for 21 November: Information and Links for week 2 | CoderDojo Athenry

When you are using Teams, please keep your microphone off unless you need to ask a question. You can have your webcam on or off, whichever you prefer.

Here are the main buttons you might need:

Two Screens

It is much easier to follow the session if you have two screens, one for the Teams window and one for your own code. Here are two ways to do this:

1. If your laptop has a HDMI port, you could connect it to a TV with a HDMI cable, or you could connect a spare computer monitor if you have one. Then press Windows and P, and select Extend. Then you can have different windows in each screen.
2. You could use your laptop for your own code, and connect to the Teams session with a separate phone or tablet.

Asking Questions

As well as the main mentor leading the Teams session, we have other mentors who can answer your questions at any time.

Either: press the Chat button and type your question

Or: press the Raise Hand button and wait for the mentor

If Chat Does Not Work

If you get an error when you try to press the Chat button, it might be because you are logged into a work or school Teams account that has chat restrictions. If so, here is a solution:

• Press Leave to leave the CoderDojo session
• Sign out of Teams – click on your picture in the top right corner to open a menu, and Sign Out is at the bottom of the menu
• Click on the link to join the CoderDojo session again, and this time join as a guest without logging into your school/work account.

# This weeks challenge is to build a working clock.

This is not just an ordinary clock though, we are going to build a clock that works in the same way as the Railway clocks works in Switzerland.

## These clocks work in the following way:

• The Clock waits for a signal from the master clock
• When it gets the signal, it moves the minute hand on by one minute (and the hour hand if necessary)
• then the second hand moves round once in about 58 seconds
• It then waits for the signal again from the master clock.

This means that all the clocks on all the Stations are synchronised exactly.

In Computer speak this is called Event Driven Programming, where the code simply waits for an Event before doing anything.

# So what’s the plan?

## We need 4 Sprites

1. For the Clock Face
2. For the Hour Hand
3. For the Minute Hand
4. For the Second Hand

You can create them however you want but this is what the Swiss railway clocks look like and I will try and create something similar.

Remember one thing, when creating the Sprites make sure they are centred correctly.

So, the clock face should be perfectly centred and then the hands should be centred near one end something like this, I have highlighted where the centre is, with the green circle.

## The code

Remember this will be event driven, so we will be using Broadcasts a lot. We will also have to calculate how far to move each hand, this means we will be using the number 360 a lot as that is one complete circle.

So just to let you know how far each hand should move:

• The Second hand will move 360 degrees for each event.
• The Minute hand will move 6 degrees for each event (360/60 minutes)
• The Hour hand will move 0.5 degree for each event (360/60 minutes/ 12 hours)

The first event will be broadcast from the Stage:

The Minute hand will receive this broadcast and move 6 degrees it will then broadcast another 2 events, one to the Hour hand and one to the second hand so they can move.

This is the code for the Minute hand which should be enough to work out the rest of the code as well.

The extra code above is to make sure the Minute hand starts in the correct position.

And one final thing which might be a little tricky, but I’ll leave it as a challenge for you, the Second hand should only take 58 seconds to go all the way around.

# Modellers – Week 1

Hi Folks,

Great to be back. Here’s a video reviewing the content from week 1. It’s for those who missed the session or just want to refresh the content for themselves.

See you all again on Saturday.

# CoderDojo Athenry Information Session 07-Nov-2020

Hello again everyone.

It was great to speak to you all last Saturday.

Here are some notes with information all about CoderDojo Athenry in PDF form.

Here’s a quick recap of everyone’s notes;

Martha told us all about the Explorers group, you can contact Martha at Martha@coderdojoathenry.onmicrosoft.com and you can find her slides here.

Oliver spoke about the Advancers group and you can contact Oliver at Oliver@coderdojoathenry.onmicrosoft.com

I talked about the Bodgers group, you contact me at Declan@coderdojoathenry.onmicrosoft.com and you can read all about the Bodgers group here.

Kieran then spoke about the Modellers group. Here is his presentation.

Kieran can be contacted at Kieran@coderdojoathenry.onmicrosoft.com.

Finally Michael spoke about the Hacker Group which will be starting in the new year. Here are his slides

Mike’s email is, yes you guessed it is, Mike@coderdojoathenry.onmicrosoft.com

We will be posting information for our first session next Saturday in the next day or two, so keep an eye out for that.

Looking forward to seeing you all again next Saturday.

Declan and the CoderDojo Athenry Mentors