Hardware Reference
In-Depth Information
DATA TYPE
CONTENTS
byte
Decimal numbers, from 0 to 255
int
Decimal numbers, from -32,768 to 32,767
(Arduino Due, from -2,147,483,648 to 2,147,483,647)
unsigned
int
Decimal numbers, from 0 to 65,535
(Arduino Due, from 0 to 4,294,967,295)
word
Decimal numbers, from 0 to 65,535
long
Decimal numbers, from -2,147,483,648 to 2,147,483,647
unsigned
long
Decimal numbers, from 0 to 4,294,967,295
short
Decimal numbers, -32,768 to 32,767
float
Floating point numbers, from -3.4028235 x 10 38 3.4028235 x 10 38
double
Floating point numbers
string
An array of char
String
Advanced arrays of char
array
A collection of variables
Also noteworthy, the Arduino Due is a relatively new device that uses a
32-bit microcontroller instead of the 8-bit AVR found in other Arduino boards.
Therefore, some of the data types are different to other Arduinos. Integers are
coded to 32-bits, meaning they can handle much larger numbers. Also, the
data type double is coded to 8 bytes on the Arduino Due and 4 bytes on other
Arduinos. Therefore, a double has more precision on an Arduino Due.
When declaring a variable, it is important to i rst specify the data type and
then the variable name. Optionally, you may assign a value by using the equal
sign. Finally, i nish with a semicolon. The following are legal declarations:
long data;
char usertext;
int pin_number = 42;
You are free to use just about any variable name, but don't use names that are
too vague. In the previous example, usertext hints that the variable contains
some text that comes from an external source. The variable pin_number suggests
that this is the pin ID for input or output operations, but data ? The dei nition
is too vast; does it contain text? Numbers? Later in your sketch, you might start
wondering what this variable contains, and you might even confuse it with
another variable with unpredictable results.
Data types work on variables but also on functions. This is described later
in the “Functions” section.
Search WWH ::




Custom Search