Lesson 4 : Coding the Skill Game
Robotics
Let's open up our code from last week and test our circuits.
If it doesn't function as intended, make sure to ask for help!
We've done a ton of circuit building, but today we begin programming
What is programming?
Programming is using the computer to solve problems. We can control computers using code, and functioning code is called a program.
Programming isn't guesswork. It isn't vague or confusing. It has to be very specific and very easy to understand. Computers are very dumb.
Most of programming is planning!
We have to set up a FRAMEWORK
What is a FRAMEWORK?
You can think of a framework as a blueprint.
It's the underlying way that our program is going to function. Before we start creating things, we have to think about what we need to create.
The best programs ARE ...
Planned out
Seperated into specific tasks
TASKS SHOULD BE FAIRLY INDEPENDENT
Logically Sound
What the heck does that mean?
It means that they should make sense. Anyone should be able to look at our program and instantly understand why we set it up in this specific way. (EVEN NON PROGRAMMERS)
We will talk more about logic later, both in this lesson and for the rest of the class
Let's list the separate parts of the program!
Let's talk! Let's design! Brainstorming time!
Here is what we are going to need (for our solution, THERE ARE INFINITE SOLUTIONS TO A PROBLEM, YOURS MIGHT ALSO WORK, EVEN IF IT'S DIFFERENT)
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
Did that seem excessive? It did.
Keep in mind, computers are dumb! They won't do anything unless we explicitly tell them to.
Let's start with the first task of our program
How are we going to make each light turn on and then off in sequence?
Turning something ON means setting a Digital Pin to TRUE
Turning something OFF means setting a Digital Pin to OFF
If we just send on and off signals, the blinks will happen too fast. What can we do to add a delay?
Where are we going to place our wait blocks?
This only happens once. How can we make it keep going on forever?
Great job guys! We've completed task 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
How can we add functionality that makes our button stop the forever loop?
We are going to set up a LISTENER EVENT
It means that the code under our listener won't run unless its specific event is triggered
What is the specific event?
What is that SOMETHING that it should do?
That's two down!
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
Let's stop here and finish up next time!
Robotics Lesson 4 : Programming our Skill Game
By scholarstem
Robotics Lesson 4 : Programming our Skill Game
- 267