Variables and Data Types
Create variable
To create a variable:
variableType variableName;
For example:
int a;
To create a variable and initialize it:
variableType variableName = initialValue;
For example:
int a = 2;
Assign value to a variable
If you have a variable declared before, you can assign some value to it:
For example:
int a; // declared previously
a = 2;
Or change the value:
int a = 3; // initalized previously
a = 2;
Variable types
char
: signed 1-byte character valuebyte
: unsigned 8-bit integerint
: signed 16-bit (on ATMEGA based boards) or 32-bit (on Arduino Due) integerunsigned int
: unsigned 16-bit (on ATMEGA based boards) or 32-bit (on Arduino Due) integerlong
: signed 32-bit integerunsigned long
: unsigned 32-bit integerfloat
: 4-byte floating point numberdouble
: 4-byte (on ATMEGA based boards) or 8-byte (on Arduino Due) floating point number
Examples:
char a = 'A';
char a = 65;
byte b = B10010;
int c = 2;
unsigned int d = 3;
long e = 186000L;
unsigned long f = millis(); // as an example
float g = 1.117;
double h = 1.117;