Download presentation
Presentation is loading. Please wait.
Published byJordan Fox Modified over 5 years ago
1
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
2
What does this program do?
SensorValue(touchSensor) == 1 means pushed, ==0 when not pushed.
3
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)
4
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.
5
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.
6
Conditions Sample
7
Conditions: Always True
8
Include an example of each RobotC symbol in your notes.
Comparison Operators Include an example of each RobotC symbol in your notes.
9
Evaluating Conditions
10
Logical Operators
11
Include these RobotC symbols and their meaning.
&& and II Include these RobotC symbols and their meaning.
12
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
13
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.
14
What does the following program do?
SensorValue(touchSensor) == 1 means pushed, ==0 when not pushed.
15
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;
16
What do you recall about the following?
< > <= >= == && || condition while if else Shaft encoder int motor[] SensorValue[] wait1Msec() Going straight.
17
Today Complete the Encoder Going Straight Activities
Work on the practice quiz. On Wednesday there is an open noted quiz.
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.