Programming Language Reference 1
Programming Language Reference 1
Construct Description
A0 – A5 Constant value for analog pins
0 - 13 Constant value for digital pins
; (semicolon) Used to end a statement
// Single line comment
/* */ Multiline comment
#define Allows the programmer to give a name to a constant value before
the program is compiled. Syntax is
#define constant_name value
#include Used to include an external library in the sketch. Syntax is
#include <LibraryFile.h>
Swarnalatha G.L, Assistant Professor, CSE dept, SSIT 42
Arduino programming language reference (contd.)
Constants
• Integer constants: Integer constants are numbers such as 123.
• Floating-point constants: Floating-point constants are numbers such as 10.0, 2.34E5
(2.34*10^5), 67e-12(67.0*10^-12).
• HIGH/LOW: When reading or writing to a digital pin there are only two possible
values a pin can take/be-set-to: HIGH and LOW. These are the same as 1 and 0.
• true/false: These are the two constants used to represent truth and falsity in the
Arduino language. true is defined as 1 and false is defined as 0. These constants are
typed in lowercase unlike HIGH and LOW.
• LED_BUILTIN: Most Arduino boards have a pin connected to an on-board LED in
series with a resistor. The constant LED_BUILTIN is the number of the pin to which
the on-board LED is connected. Most boards have this LED connected to digital pin
13.
• INPUT/OUTPUT: Pins can be configured as INPUT or OUTPUT. Pin configured as an
INPUT can only be read. Pin configured as an OUTPUT can only be set.
Swarnalatha G.L, Assistant Professor, CSE dept, SSIT 43
Arduino programming language reference (contd.)
Data types
• int: On the Arduino UNO, an int stores a 16-bit (2-byte) value. This yields a range
of -32,768 to 32,767 (minimum value of -2^15 and a maximum value of ((2^15) –
1)). Syntax is
int variable_name = value;
• float: A float stores 32-bits (4-byte) of information. These can be as large as
3.4028235E+38 and as low as -3.4028235E+38. Syntax is
float variable_name = value;
• char: A data type used to store a character value. Character literals are written in
single quotes, like ‘A’. Multiple characters (strings) are written in double quotes,
like "ABC". Syntax is
char variable_name = value;
• double: Double precision floating point number. On the Arduino UNO boards, this
occupies 4 bytes. That is, the double implementation is exactly the same as the
float, with no gain in precision. Syntax is
double variable_name = value;
Swarnalatha G.L, Assistant Professor, CSE dept, SSIT 44
Arduino programming language reference (contd.)
• long: Long variables are extended size variables for number storage, and store 32
bits (4 bytes) value from -2,147,483,648 to 2,147,483,647. Syntax is
long variable_name = value;
• short: A short is a 16-bit data type. On all Arduino boards a short stores a 16-bit
(2-byte) value. This yields a range of -32,768 to 32,767 (minimum value of -2^15
and a maximum value of (2^15) - 1). Syntax is
short variable_name = value;
• unsigned int: On the Arduino UNO boards, unsigned integers are the same as
integers in that they store a 2 byte value. Instead of storing negative numbers
however they only store positive values, yielding a useful range of 0 to 65,535
((2^16) - 1). Syntax is
unsigned int variable_name = value;
• byte: A byte stores an 8-bit unsigned number, from 0 to 255. Syntax is
byte variable_name = value;
Swarnalatha G.L, Assistant Professor, CSE dept, SSIT 45
Arduino programming language reference (contd.)
• unsigned long: Unsigned long variables are extended size variables for number
storage, and store 32 bits (4 bytes). Unlike standard longs unsigned longs won’t
store negative numbers, making their range from 0 to 4,294,967,295 (2^32 - 1).
Syntax is
unsigned long variable_name = value;