cc.arduino
Class Arduino

java.lang.Object
  extended by cc.arduino.Arduino

public class Arduino
extends java.lang.Object

Together with the Firmata 2 firmware (an Arduino sketch uploaded to the Arduino board), this class allows you to control the Arduino board from Processing: reading from and writing to the digital pins and reading the analog inputs.


Nested Class Summary
 class Arduino.FirmataWriter
           
 class Arduino.SerialProxy
           
 
Field Summary
static int ANALOG
          Constant to set a pin to analog mode (in a call to pinMode()).
static int HIGH
          Constant to write a low value (0 volts) to a pin (in a call to digitalWrite()).
static int I2C
          Constant to set a pin to I2C mode (in a call to pinMode()).
static int INPUT
          Constant to set a pin to input mode (in a call to pinMode()).
static int LOW
          Constant to write a high value (+5 volts) to a pin (in a call to digitalWrite()).
static int OUTPUT
          Constant to set a pin to output mode (in a call to pinMode()).
static int PWM
          Constant to set a pin to PWM mode (in a call to pinMode()).
static int SERVO
          Constant to set a pin to servo mode (in a call to pinMode()).
static int SHIFT
          Constant to set a pin to shiftIn/shiftOut mode (in a call to pinMode()).
 
Constructor Summary
Arduino(processing.core.PApplet parent, java.lang.String iname)
          Create a proxy to an Arduino board running the Firmata 2 firmware at the default baud rate of 57600.
Arduino(processing.core.PApplet parent, java.lang.String iname, int irate)
          Create a proxy to an Arduino board running the Firmata 2 firmware.
 
Method Summary
 int analogRead(int pin)
          Returns the last known value read from the analog pin: 0 (0 volts) to 1023 (5 volts).
 void analogWrite(int pin, int value)
          Write an analog value (PWM-wave) to a digital pin.
 int digitalRead(int pin)
          Returns the last known value read from the digital pin: HIGH or LOW.
 void digitalWrite(int pin, int value)
          Write to a digital pin (the pin must have been put into output mode with pinMode()).
 void dispose()
           
static java.lang.String[] list()
          Get a list of the available Arduino boards; currently all serial devices (i.e.
 void pinMode(int pin, int mode)
          Set a digital pin to input or output mode.
 void servoWrite(int pin, int value)
          Write a value to a servo pin.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

INPUT

public static final int INPUT
Constant to set a pin to input mode (in a call to pinMode()).

See Also:
Constant Field Values

OUTPUT

public static final int OUTPUT
Constant to set a pin to output mode (in a call to pinMode()).

See Also:
Constant Field Values

ANALOG

public static final int ANALOG
Constant to set a pin to analog mode (in a call to pinMode()).

See Also:
Constant Field Values

PWM

public static final int PWM
Constant to set a pin to PWM mode (in a call to pinMode()).

See Also:
Constant Field Values

SERVO

public static final int SERVO
Constant to set a pin to servo mode (in a call to pinMode()).

See Also:
Constant Field Values

SHIFT

public static final int SHIFT
Constant to set a pin to shiftIn/shiftOut mode (in a call to pinMode()).

See Also:
Constant Field Values

I2C

public static final int I2C
Constant to set a pin to I2C mode (in a call to pinMode()).

See Also:
Constant Field Values

LOW

public static final int LOW
Constant to write a high value (+5 volts) to a pin (in a call to digitalWrite()).

See Also:
Constant Field Values

HIGH

public static final int HIGH
Constant to write a low value (0 volts) to a pin (in a call to digitalWrite()).

See Also:
Constant Field Values
Constructor Detail

Arduino

public Arduino(processing.core.PApplet parent,
               java.lang.String iname)
Create a proxy to an Arduino board running the Firmata 2 firmware at the default baud rate of 57600.

Parameters:
parent - the Processing sketch creating this Arduino board (i.e. "this").
iname - the name of the serial device associated with the Arduino board (e.g. one the elements of the array returned by Arduino.list())

Arduino

public Arduino(processing.core.PApplet parent,
               java.lang.String iname,
               int irate)
Create a proxy to an Arduino board running the Firmata 2 firmware.

Parameters:
parent - the Processing sketch creating this Arduino board (i.e. "this").
iname - the name of the serial device associated with the Arduino board (e.g. one the elements of the array returned by Arduino.list())
irate - the baud rate to use to communicate with the Arduino board (the firmata library defaults to 57600, and the examples use this rate, but other firmwares may override it)
Method Detail

dispose

public void dispose()

list

public static java.lang.String[] list()
Get a list of the available Arduino boards; currently all serial devices (i.e. the same as Serial.list()). In theory, this should figure out what's an Arduino board and what's not.


digitalRead

public int digitalRead(int pin)
Returns the last known value read from the digital pin: HIGH or LOW.

Parameters:
pin - the digital pin whose value should be returned (from 2 to 13, since pins 0 and 1 are used for serial communication)

analogRead

public int analogRead(int pin)
Returns the last known value read from the analog pin: 0 (0 volts) to 1023 (5 volts).

Parameters:
pin - the analog pin whose value should be returned (from 0 to 5)

pinMode

public void pinMode(int pin,
                    int mode)
Set a digital pin to input or output mode.

Parameters:
pin - the pin whose mode to set (from 2 to 13)
mode - either Arduino.INPUT or Arduino.OUTPUT

digitalWrite

public void digitalWrite(int pin,
                         int value)
Write to a digital pin (the pin must have been put into output mode with pinMode()).

Parameters:
pin - the pin to write to (from 2 to 13)
value - the value to write: Arduino.LOW (0 volts) or Arduino.HIGH (5 volts)

analogWrite

public void analogWrite(int pin,
                        int value)
Write an analog value (PWM-wave) to a digital pin.

Parameters:
pin - the pin to write to (must be 9, 10, or 11, as those are they only ones which support hardware pwm)
value - the value: 0 being the lowest (always off), and 255 the highest (always on)

servoWrite

public void servoWrite(int pin,
                       int value)
Write a value to a servo pin.

Parameters:
pin - the pin the servo is attached to
value - the value: 0 being the lowest angle, and 180 the highest angle