This article details the most common data types used in Arduino programming.
Data types:
Array
A collection of variables that can be accessed via an index number.
Below are the various methods of declaring arrays:
Key:
int myInts: declares an array without initializing it.
int myPins: declares an array without specifying size.
int mySensVals: declares an array and specifies size.
Bool
Can hold either a true or false value.
Syntax: bool var = val
Var refers to a variable.
Val is the value you assign to that variable.
Char
A data type used to store a character value.
Character literals, or just letters, are enclosed by single quotes, whereas a collection of characters, also known as a string, uses double quotes.
Examples:
char myLetter = 'A';
char myInitials = "AL";
Byte
Stores an eight bit integer number, from 0-255.
Syntax: byte var = val
'var' and 'val' have the equivalent meaning as they do with respect to the bool data type.
Float
Data type for floating-point numbers, or numbers with decimal points.
Often used to approximate values as they have greater resolution (precision) than integers.
Syntax: float var = val
Example:
float pi = 3.14
Warnings:
Floating-point arithmetic takes longer to compute than it would if integers were used.
The float data type has 6-7 digits of precision (note: not digits after the decimal point, but total digits).
Int
Primary data type for number storage.
Syntax: int var = val
Void
Used only in function declarations (ie void loop, void setup)
Void Indicates that the following function is not expected to return any information to the function from which it was called.
For example, although there are actions performed within the void setup and void loop functions, no information is returned to the larger program.
Conversions - converting one data type to another:
byte(x) converts the value x into a byte data type
char(x) converts the value x into a char data type
float(x) converts the value x into a float data type
int(x) converts the value x into an int data type
etc
Comentarios