Topics Covered
Color Sensor Values
The VEX IQ Color sensor is capable of several different modes:Real Robot users
Virtual Robot users
As the color sensor is pointed at differently colored objects, the values on the screen update. Certain hue values correspond with certain color names. If the lighting in the environment varies, so do the sensor readings. |
Another Else Statement
Right now, the program tells the robot to turn left if the color sensor detects red and to turn right if it detects any other color.
With the updated program, the robot would first detect for red. If it doesn't detect red, it would then detect for blue. If it doesn't detect blue, it would then move to the end of the program, thus doing absolutely nothing.![]() We can now just add another else statement to the program. This else would run when the if statement is false and the else if is also false. In other words, when the robot does not detect either red or blue. If the robot detects any other color, let's just tell it to move forward. ![]() Save the program and run it. The robot should now turn left if the color is red, right if the color is blue and move straight if the color sensor detects any other color. Keep in mind, we can add more than one else if to our programs. |
Did you know?
Concept of Whitespace![]() |
White space is used by programmers to keep their code clean and organized. White space is ignored the robot or compiler. White space includes indentation, spaces, and new lines within a program. Indentation is often used to signify which programming structures (tasks, conditionals, loops, etc.) and commands are embedded within other programming structures. Blank lines are often used to separate different behaviors within a long program. |
Did you know?
Semicolon vs. No Semicolon![]() |
Up until now, you may have noticed that certain commands end with semicolons, and some do not. |
|
![]() |
Loops and conditional statements like “if/else” create structure and decision making within a program. |
Did you know?
Conditional Structures![]() |
If statements control the flow of the program by containing blocks of code. |
|
![]() |
Code "inside" of an if statement is denoted by a set of curly braces. |
Did you know?
If Statements vs. Wait Untils![]() |
A "waitUntil" command waits – it does nothing – until the condition within the parenthesis is true and then it continues on with the program.
|
|
![]() |
An "if" statement like the one in this program, on the other hand, says: |
Mini Challenge 1: Signal Reader
Program the robot so that it travels to the middle of the challenge table where there will be a color tile. The robot then makes a decision about its next movement based upon the color of the color tile.
|
Mini Challenge 2: Ladder Drill
Program the robot to make from one end of a table to the other side, using its color sensor.
If the robot detects red, have it move backwards 1 rotation.
If the robot detects green, have it move forward 4 rotations.
|