20
4.
Let’s do the example as shown in Figure 3.3.
Figure 3.3
5.
Things to note about the if statement in the example:
a.
The logical test is == not just =. A single = is an assignment statement.
b.
In the statement
var1 = 1
, the value of 1 is assigned to the variable
var1
. In the
statement
var1 == 1
, the value of
var1
is compared to the value of 1 and returns a
“true” if the values are equal and “false” if the values are not equal.
6.
Take a few minutes to change the value of
var1
in the example to see what happens to the
value of
var2
. Does the output make sense?
7.
The logical operators are:
a.
== test if equal
b.
!= test if not equal
c.
< test if less than
d.
> test if greater than
e.
<= test if less than or equal to
f.
>= test if greater than or equal to
void setup()
{
Serial.begin(9600);
}
void loop()
{
int var1, var2;
var1 = 1;
var2 = 1;
if( var1 == 1)
{
var2 = 2;
}
Serial.print("var1 = ");
Serial.print(var1, DEC);
Serial.print(" var2 = ");
Serial.println(var2, DEC);
Serial.println(" ");
delay(1000);
}
Summary of Contents for Pi-Bot v2.00
Page 67: ...67 Figure 6 15 ...
Page 78: ...78 UltraSonicSensorTestwithLED Program ...
Page 80: ...80 ObstacleAvoidance Program ...
Page 82: ...82 ObstacleAvoidancewithLED Program ...
Page 83: ...83 ObstacleAvoidancewithLED Program CONTINUED ...
Page 90: ...90 Download and run the following program LineFollowing Program ...
Page 91: ...91 LineFollowing Program CONTINUED ...
Page 94: ...94 AdvancedLineFollowing Program CONTINUED ...
Page 95: ...95 AdvancedLineFollowing Program CONTINUED ...
Page 96: ...96 AdvancedLineFollowing Program CONTINUED ...
Page 110: ...Appendix B Complete Pi Bot Wiring Schematic ...