Lesson 5 : Finishing the Skill Game

Robotics

Let's get our boards plugged in and set up in S4A

Let's open up our project from last week

Let's test our boards and our code

Let's go over our task list

A way to turn on each light, and then turn it off.

A way to recognize whether or not it is the middle light.

A way to stop the lights.

A way to make 2 different sounds, one when you land in the middle and one when you don't

A way to restart our game once it has finished

First two are done, so how can we check whether or not the light we stopped on is the correct light?

We refer to something's exact value at a given time as its state.

What are some states you've been in/can be in?

States can change!

Whether or not something is true or false represents two possible states.

For our circuit, the STATES we care about are 

Whether the light is on

Whether the light is off

We can store this state as a variable. Then we can check the variables value( T or F )

What's a variable?

A variable can be thought of a box. In this box, we can put anything we want. The only thing that really matters is the name on the box

Let's create a variable and call it middleActive.

MAKE YOUR VARIABLE NAMES LOGICAL. THEY SHOULD MAKE SENSE TO EVERYONE. DON'T GIVE VARIABLES WEIRD/UNINTELLIGIBLE NAMES

Now that we have our variable, let's store our middle LED's state. It should be set to TRUE when it is ON and set to FALSE when it is OFF.

That's three down two to go!

A way to turn on each light, and then turn it off.

A way to recognize whether or not it is the middle light.

A way to stop the lights.

A way to make 2 different sounds, one when you land in the middle and one when you don't

A way to restart our game once it has finished

Now we want to make it do two different things. One if middleActive is True and one if it isn't.

How can we do that?

The answer was right there! We are going to use an IF/THEN block. 

WE ALWAYS USE IF/THEN BLOCKS IF WE WANT OUR PROGRAM TO ONLY DO CERTAIN THINGS WHEN SPECIFIC CONDITIONS ARE TRUE OR FALSE.

It should play a high pitched tone if we land on the middle light, and a low pitched tone if it's not.

Last one!

A way to turn on each light, and then turn it off.

A way to recognize whether or not it is the middle light.

A way to stop the lights.

A way to make 2 different sounds, one when you land in the middle and one when you don't

A way to restart our game once it has finished

This task is a simple, but we have to take care of one oversight. If we want to restart the game, we will have to turn off all the lights! Let's do that.

Now that that is done, we have to set up another EVENT LISTENER

We don't want to have to click on the green flag to start our game over, that is hard and tedious

This EVENT should be easy to access. We're going to bind it to the Spacebar!

We've finished! Congratulations on completing your first project!

What did we learn? 

Any questions?

Export your projects!

Take apart your circuit and put away the pieces neatly!

Until next time! 

Robotics Lesson 5 : Finishing our Skill Game

By scholarstem

Robotics Lesson 5 : Finishing our Skill Game

  • 280