Operators: are programming blocks used to perform mathematical operations or logical comparisons.
These blocks allow you to manipulate numbers and make decisions based on conditions.
Such as:
-> Logical operators are used to create more complex conditions.
-> They are especially useful in decision-making and branching structures, allowing your robot to make intelligent choices based on sensor inputs or other conditions.
For example:
-> Is it true that fruit AND fried chicken are healthy?
No. So, this is false
-> Is it true that apple AND strawberry are healthy?
Yes. So, this is true
"AND" operator combines two conditions and returns true only if both conditions are true. It's represented by the symbol "&&."
For example:
Condition 1: Touch sensor is pressed.
Condition 2: Color sensor detects red.
Combined Condition: Touch sensor is pressed && Color sensor detects red.
1- Repeat [Robot move backward at the speed of 50%]
2- Until [Color Sensor detect "red" AND Ultrasinic distance "less than 15cm"]
3- Stop moving
-> Robot did not stop because the condition it's not met. So, it's false.
-> Because ONLY ultrasonic sensor "less than 15cm" BUT not Color sensor.
BOTH condition have to be fulfill in order to meet the condition.
-> [Color Sensor detect "red" AND Ultrasinic distance "less than 15cm"] is detected. Condition it's met.
-> Robot Stop moving
IF
1- If [Color Sensor detect "red" AND Ultrasinic distance "less than 15cm"] condition is met
2- Robot move FORWARD at the speed of 50%
ELSE
1- If [Color Sensor detect "red" AND Ultrasinic distance "less than 15cm"] condition NOT met
2- Robot move BACKWARD at the speed of 50%
-> Robot did not move forward because the condition it's not met. So, it's false.
-> Because ONLY ultrasonic sensor "less than 15cm" BUT not Color sensor.
BOTH condition have to be fulfill in order to meet the condition.
So, robot move BACKWARD.
-> [Color Sensor detect "red" AND Ultrasinic distance "less than 15cm"] is detected. Condition it's met.
-> Robot move FORWARD
For example:
->Is it true that ice cream OR fried chicken: food?
Yes. So, this is true
-> Is ice cream OR fried chicken: machines?
No. So, this is false
"OR" operator combines two conditions and returns true if at least one of the conditions is true. It's represented by the symbol "||".
For example:
Condition 1: Color sensor detects blue
Condition 2: Color sensor detects red
Combined Condition: Color sensor detects blue || Color sensor detects red.
1- Repeat [Robot move backward at the speed of 50%]
2- Until [Color Sensor detect "red" AND Ultrasinic distance "less than 15cm"]
3- Stop moving
The robot either [Color Sensor detect "red" OR Ultrasinic distance "less than 15cm"]. Color sensor detected "red", so condition is met.
The robot either [Color Sensor detect "red" OR Ultrasinic distance "less than 15cm"]. Ultrasonic sensor detected "distance less than 15cm", so condition is met.
IF
1- If [Color Sensor detect "red" AND Ultrasinic distance "less than 15cm"] condition is met
2- Robot move FORWARD at the speed of 50%
ELSE
1- If [Color Sensor detect "red" AND Ultrasinic distance "less than 15cm"] condition NOT met
2- Robot move BACKWARD at the speed of 50%
The robot either [Color Sensor detect "red" OR Ultrasinic distance "less than 15cm"]. Color sensor detected "red", so condition is met.
The robot either [Color Sensor detect "red" OR Ultrasinic distance "less than 15cm"]. Ultrasonic sensor detected "distance less than 15cm", so condition is met.