Intro
Construction
Scrooge McRobot - LEGO Mindstorms EV3 coin counting robot
This robot was made to count coins. The door slides, making the gyro sensor rotate, and by doing that, allowing the robot to measure the size of the coin that enters the safe. By changing the points where the gyro's beam connects, the sensor's thresholds change.
Programming
Do you remember: Importing my block in a LEGO EV3 Project
Peak Angle Detection
This MyBlock waits for the color sensor to detect any color and returns the peak angle the gyro detected at that time. This program is meant to work with a coin counting robot named Scrooge McRobot.
Avoid using the loop block today, unless the task tells you to use that block specifically!
What is a variable
Variables are little boxes within the computer, that store some important for us information. Imagine the following situation: you own a bar which offers the best lemonade in town. The lemonade is stored in a small non-transparent barrel, so one can not see how much lemonade there is inside. It is important that you always have fresh lemonade - if the lemonade finish before the next delivery, you will not have lemonade and your customers will be unsatisfied, if you order too early you risk that the lemonade would not be fresh and the customers will not be satisfied again. So the solution is to take a white piece of paper, which will be your variable, and put down to amount of lemonade you have. When a customer order a lemonade, you subtract his order and put down the new amount of lemonade. You repeat that process until you are left with lets say 10 liters of lemonade, when you order a new barrel.
As mentioned in the above situation, the white piece of paper is a variable. It stores a valuable for us information i.e... the amount of lemonade inside the barrel. If we need to program this operation we will have to read the number written on the paper (or in the variable) subtract the amount we have sold and write down on the paper (or in the variable) the new amount. We do not know those values before hand, but they does not matter. We will repeat the same action until the variable has value less or equal to 10.
Creating a new variable
The first step for creating a variable is taking a variable block and put it on the canvas. The block is the first one under the red (data) palette.
Variable Name
All variables must have their names as a way to distinguish them. That is why it is extremely important to choose a proper name for the variable. At first, that may seem as a silly task and you will prefer to name your variable with names such as "a" or "var1" or "asdf".
However, once you start working on more complicated tasks, where you will need multiple variables you will get into the situation where you have a project with variables that are hard to distinguish. Probably you will be able to know what a and b store during the time you work on your program, but after a few days it would be impossible, set aside for someone else. It is important the variable names are descriptive enough so that another person could easily understand your program. That program looks a lot better:
To set the name of the variable click on the upper right corner of the block and from the list, select Add Variable
Then enter the name you have chosen in the popup window and select ok.
Тhe last step of creating a variable is to set its initial value. The example above shows how to create a variable named "count" with initial value 0.
Variable Initialization
Initializing a variable means giving it a starting value/data.
Initializing a variable begins by adding a variable block from the red palette:
Every variable must have its own name, with which it can be distinguished. When you want to change the information a variable store inside, you'll need to call it by name, and that's why it's a good practice to give the variables, names that hint what information they store. Also, they have to start with some information already stored in them.
In this example, you can see how a variable with the name "count" is initialized with the starting value of 15:
Reading and Writing into Variables
Once you have initialized your variable you will need to read and write it. That is why the variable block has two modes. If you want to create a new variable or want to replace the old value of a variable and write a new one, choose Write from the drop-down menu.
If you want to read the current value stored in the variable choose Read from the drop-down menu.
Tasks to finish a class
- Take pictures and make videos of your robots
- Disassemble and arrange the robot
- Arrange your workplace
- It is important to arrange the electronics of the robots on the cover of the box.
- Wind up the programming cable so that it is assembled.
- Put the robot cables next to the electronics.
- Wind up the mouse cable around the mouse.
- Wind up the cable of the laptop charger in a way that your teacher will show you.
- When you turn off the computer, leave it next to the robot box.
- Turn off all programs on your computer
- Exit FLLCasts
- Shut down your computer
- Put your chair under the desk.