We have to give our robot some sources to derive truth values from, we do this with Testing Statements.
The simplest form of testing statement is testing a value of a variable representing a sensor.
Remember when we talked about Truth Values, I said that true had a value of 1 and false had a value of 0.
However, when you test a value of a variable it will always be true if the variable has a non-zero value.
g=3 [g is assigned the value of 3]
g is true.
f=5 [f is assigned the value of 5]
f is true.
h=0 [h is assigned the value of 0]
h is false.
You are more likely to use them when incorporating sensors.
So these examples will look more like these:
A=analog10(3); // A is true when the analog sensor 3 detects anything.
black_button as well as the digital sensors are true when being pressed.
Other, common forms of testing statements arecomparisons using logic andinequalities.
- Is A equal to B? [A==B]
- Is A greater than B? [A>B]
- Is A less than B? [A<B]
- Is A greater than or equal to B? [A>=B]
- Is A less than or equal to B? [A<=B]
- Is A not equal to B? [A!=B]