Book Image

OpenFrameworks Essentials

Book Image

OpenFrameworks Essentials

Overview of this book

Table of Contents (19 chapters)
openFrameworks Essentials
Credits
Foreword
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Programming an Arduino board


Let's start with the following steps:

  1. Download the Arduino IDE from www.arduino.cc (the current version is 1.0.6).

  2. Unzip and run it.

  3. Go to the File menu and click on New. A new window with an empty sketch (that is, an Arduino program) will be created.

  4. Fill it with the following code:

    void setup() {
      Serial.begin(9600);
    }
    
    void loop() {
      int analogIn = analogRead(A0);
      float value = analogIn / 1023.0;
      Serial.println(value);
    }

    Tip

    This code is written in the Arduino language. This language resembles the C, C++, and Java languages. It includes special constants, functions, and objects related to specific hardware capabilities of the Arduino board, such as analog inputs and serial ports.

    This code consists of two functions, setup() and loop(). Both functions are required to be defined in any Arduino sketch. The setup() function is called once when the board is started (or restarted). After that, the loop() function is called repeatedly until the board is powered off...