RobotC While loop When and how to use the while loop Get out your notes: Head the paper Your Name While / Conditions / Calculating Distances RobotC While loop When and how to use the while loop Setting up and understanding conditions Calculating Distances using the Shaft Encoder
What does this program do? SensorValue(touchSensor) == 1 means pushed, ==0 when not pushed.
While loop When to use it: Examples When you want to repeat something an unknown number of times AND It might not occur at all Examples Going forward while on a white line Repeating something forever, while (true)
How it works while (condition) { } //Commands When the compiler gets to the ‘while’ line, it checks to see if the condition is true. If the condition is true, it repeats the commands, if it is false, it leaves the while loop.
Conditions Conditions are either true or false (boolean) ROBOTC control structures that make decisions about which pieces of code to run, such as while loops and if-else conditional statements, always depend on a (condition) to make their decisions. ROBOTC (conditions) are always Boolean statements.
Conditions Sample
Conditions: Always True
Include an example of each RobotC symbol in your notes. Comparison Operators Include an example of each RobotC symbol in your notes.
Evaluating Conditions
Logical Operators
Include these RobotC symbols and their meaning. && and II Include these RobotC symbols and their meaning.
Your turn: true, false, or crash? Let x = 10, y = 5 and z = 30 for the following examples. ( 5 > 10) (8 < 3) || (9 >=6) ((6-2) > 1) && (5*3 <30)) (1 == 1) (12 > 15) || ((6<10) && (5>2) ) (20 > x > 5) (x < y) and (z >2) (x>z ) && (x < y) Number 1-8 in your notes and copy the condition and the result
Your turn: Write the condition Include your answers to the conditions in your notes. True if SensorValue[leftEncoder] gives a value less than 30. True if SensorValue[rightEncoder] is not zero. True if SensorValue[leftEncoder] is in the range 50 to 90. True if SensorValue(rightEncoder] is greater than 40 and SensorValue[leftEncoder] is less than 30.
What does the following program do? SensorValue(touchSensor) == 1 means pushed, ==0 when not pushed.
How far will this robot move if it has 4. 7 cm radius wheels How far will this robot move if it has 4.7 cm radius wheels? (Same as the clawbot) SensorValue[rightEncoder] = 0; while(SensorValue[rightEncoder] < 360) { motor[rightMotor] = 63; motor[leftMotor] = 63; } motor[rightMotor] = 0; motor[leftMotor] = 0;
What do you recall about the following? < > <= >= == && || condition while if else Shaft encoder int motor[] SensorValue[] wait1Msec() Going straight.
Today Complete the Encoder Going Straight Activities Work on the practice quiz. On Wednesday there is an open noted quiz.