Datasheet
// (single line comment)
It is often useful to write notes
to yourself as you go along
about what each line of code
does. To do this type two
forward slashes and everything
until the end of the line will be
ignored by your program.
{ } (curly brackets)
Used to define when a block
of code starts and ends (used
in functions as well as loops).
04
03 PROG
programming
primer
.:A Small Programming Primer:.
The Arduino is programmed in the C language. This is a quick little primer targeted at people
who have a little bit of programing experience and just need a briefing on the idiosyncracies of C
and the Arduino IDE. If you find the concepts a bit daunting, don't worry, you can start going
through the circuits and pick up most of it along the way. For a more in-depth intro, the
Arduino.cc website is a great resource.
STRUCTURE
void setup(){ }
All the code between the two
curly brackets will be run once
when your Arduino program
first runs.
Each Arduino program
(often called a sketch) has
two required functions
(also called routines).
void loop(){ }
This function is run after setup
has finished. After it has run
once it will be run again, and
again, until power is removed.
SYNTAX
; (semicolon)
Each line of code must be
ended with a semicolon (a
missing semicolon is often
the reason for a program
refusing to compile).
One of the slightly
frustrating elements of C is
its formatting requirements
(this also makes it very
powerful). If you remember
the following you should be
alright.
/* */(multi line comment)
If you have a lot to say you can
span several lines as a
comment. Everything between
these two symbols will be
ignored in your program.
A program is nothing more
than instructions to move
numbers around in an
intelligent way. Variables are
used to do the moving.
long (long)
Used when an integer is not
large enough. Takes 4 bytes (32
bits) of RAM and has a range
between -2,147,483,648 and
2,147,483,647.
int (integer)
The main workhorse, stores a
number in 2 bytes (16 bits).
Has no decimal places and will
store a value between -32,768
and 32,767.
boolean (boolean)
A simple True or False
variable. Useful
because it only
uses one bit of
RAM.
char (character)
Stores one character using the
ASCII code (ie 'A' = 65). Uses
one byte (8 bits) of RAM. The
Arduino handles strings as an
array of char’s.
float (float)
Used for floating point math
(decimals). Takes 4 bytes (32
bits) of RAM and has a range
between -3.4028235E+38
and 3.4028235E+38.
ARDUINO PROGRAMMING IN BRIEF
VARIABLES