Introduction to Programming the Arduino

The programming language used for the Arduino is based primarily on the C language. Some features of the C++ language may be used in more advanced programming features but are not used in this introduction.

Each program must include two parts for it to be valid, the setup and loop functions. Any statements included in a setup function are only run once by the program. Any statements in the loop function are executed over and over.

/*--- Minimum Arduino programming functions, setup and loop  ---*/

void setup()
{
}

void loop()
{
}

The first line in the above program is a comment. The comment is not really required but are helpful in explaining what a program is supposed to do.

/*— Minimum Arduino programming statements —*/
Comments can have two forms. The previous comment starts with the /* characters and continues until the ending characters */ are found.

/* This style of
comment can
cross multiple lines
*/

The other comment form is with the double slash characters

// This is a comment too but is only on a single line in the program.

Comments with the // characters can begin anywhere on a line and are often used following a programming statement.

Verify and Compile

Using the Sketch → Verify/Compile command to check your work.

Arduino Sketch - Verify/Compile

Arduino Sketch -> Verify/Compile

If everything compiles successfully the Arduino’ programming environment shows the message “Done compiling”. When the sketch compiles without errors it also shows the message stating the Binary sketch size.

Sketch Successfully Compiled

Sketch Successfully Compiled

This simple program will compile properly but doesn’t do anything useful. It just shows the bare minimum needed to create a program.

(c) 2009 – Vince Thompson
Advertisements

Tags: , ,

2 Responses to “Introduction to Programming the Arduino”

  1. LEDBlink Arduino Program « DIY Robotics Lab Says:

    […] described in the related article “Introduction to Programming the Arduino“, the programming language used for the Arduino is based primarily on the C […]

  2. Correcting Arduino Compiler Errors « DIY Robotics Lab Says:

    […] article “Introduction to Programming the Arduino” describes the comment styles used by C programs. The error on line 1 is caused by mixing the […]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: