Datasheet
Chapter 1 • Your Shield-Bot’s Brain
24 • Robotics with the BOE Shield-Bot
Open the Arduino Reference
Still have questions? Try the Arduino Language Reference. It’s a set of pages with links you
can follow to learn more about
setup, loop, print, println, delay, and lots of other
functions you can use in your sketches.
If you are using the Arduino IDE, click Help and select Reference.
If you are using codebender : edu, go to the following web address:
https://www.arduino.cc/en/Reference/HomePage
Try looking up whichever term you might have a question about. You’ll find
setup, loop,
and
delay on the main reference page.
If you’re looking for links to
print or println, you’ll have to find and follow the Serial link
first.
Activity 3: Store and Retrieve Values
Variables are names you can create for storing, retrieving, and using values in the Arduino
microcontroller’s memory. Here are three example variable declarations from the next
sketch:
int a = 42;
char c = 'm';
float root2 = sqrt(2.0);
The declaration int a = 42 creates a variable named a. The int part tells the Arduino
software what type of variable (or data type) it’s dealing with. The
int type can store
integer values ranging from -32,768 to 32,767. The declaration also assigns
a an initial
value of 42. (The initial value is optional, you could instead just declare
int a, and then
later assign the value 42 to a with
a = 42.)
Next,
char c = 'm' declares a variable named c of the type char (which is for storing
characters) and then assigns it the value 'm'.
Then,
float root2 = sqrt(2.0) declares a variable named root2. The variable type
is
float, which can hold decimal values. Here, root2 is initialized to the floating-point
representation of the square root of two:
sqrt(2.0).
Now that your code has stored values to memory, how can it retrieve and use them? One
way is to simply pass each variable to a function’s parameter. Here are three examples,
where the
Serial.println(val) function displays the value of the variable inside the
parentheses.