16
In a computer, variables are used to store numbers. A bit variable can take on two values, 0 and
1, and is typically used as a true/false flag in a program. A byte variable can take on integer
values 0-255 decimal while a 16-bit word variable can take on integer values 0-65,535. Variables
can be either signed (positive and negative values) or unsigned (positive only).
7 Arduino Programming Language
The Arduino runs a simplified version of the C programming language, with some extensions for
accessing the hardware. In this guide, we will cover the subset of the programming language that
is most useful to the novice Arduino designer. For more information on the Arduino language,
see the Language Reference section of the Arduino web site,
http://arduino.cc/en/Reference/HomePage.
All Arduino instructions are one line. The board can hold a program hundreds of lines long and
has space for about 1,000 two-byte variables. The Arduino executes programs at about 300,000
source code lines per sec.
7.1 Creating a Program
Programs are created in the Arduino development environment and then downloaded to the
Arduino board. Code must be entered in the proper syntax which means using valid command
names and a valid grammar for each code line. The compiler will catch and flag syntax errors
before download. Sometimes the error message can be cryptic and you have to do a bit of
hunting because the actual error occurred before what was flagged.
Although your program may pass cleanly through the syntax checker, it still might not do what
you wanted it to. Here is where you have to hone your skills at code debugging. The Arduino did
what you told it to do rather than what you wanted it to do. The best way to catch these errors is
to read the code line by line and be the computer. Having another person go through your code
also helps. Skilled debugging takes practice.
7.2 Program Formatting and Syntax
Programs are entered line by line. Code is case sensitive which means "myvariable" is different
than "MyVariable".
Statements are any command. Statements are terminated with a semi-colon. A classic mistake is
to forget the semi-colon so if your program does not compile, examine the error text and see if
you forgot to enter a colon.
Comments are any text that follows “//” on a line. For multi-line block comments, begin with
“/*” and end with “*/”
Constants are fixed numbers and can be entered as ordinary decimal numbers (integer only) or
in hexadecimal (base 16) or in binary (base 2) as shown in the table below