Datasheet

Chapter 1 Your Shield-Bot’s Brain
28Robotics with the BOE Shield-Bot
Create, save, and run SimpleMath on your Arduino.
Check the result in the Serial Monitor. Is it correct?
// Robotics with the BOE Shield - SimpleMath
void setup()
{
Serial.begin(9600);
int a = 89;
int b = 42;
int c = a + b;
Serial.print("a + b = ");
Serial.println(c);
}
void loop()
{
// Empty, no repeating code.
}
Fit your variables to the result values you need to store. This will use less memory so you
can write larger sketches that will execute more efficiently.
If you need to work with decimal point values, use
float.
If you are using integer values (counting numbers), choose
byte, int, or long.
If your results will always be an unsigned number from 0 to 255, use
byte.
If your results will not exceed 32,768 to 32,767, an
int variable works.
If you need a larger range of values, try a
long variable instead. It can store
values from -2,147,483,648 to 2,147,483,647.
Your Turn Experiment with Other Arithmetic Operators
You still have , *, /, and % to try out!
Replace the addition (
+) operator with the subtraction () operator. Replace
both instances of
+ in the sketch.
Run the modified sketch and verify the result in the Serial Monitor.
Repeat for the multiplication (
*), division (/) and modulus (%) operators.
Floating Point Math
Imagine entering your BOE Shield-Bot in a contest where you have to make it travel in a
circle, but the radius will only be announced a few minutes before the contest. You’d have an
advantage if your code could calculate the circumference of the circle. The formula is 2 × π ×