cc.arduino
Class Arduino

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

public class Arduino
extends java.lang.Object

Together with the firmata 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.SerialProxy
           
 
Field Summary
static int HIGH
          Constant to write a low value (0 volts) to a pin (in a call to digitalWrite()).
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()).
 
Constructor Summary
Arduino(PApplet parent, java.lang.String iname, int irate)
          Create a proxy to an Arduino board running the firmata firmware (used with PDuino).
 
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 servoAttach(int pin)
          Initialize servo timer routines on a pin.
 void servoDetach(int pin)
          Stop pulse output to a pin.
 void servoSetMaxPulseTime(int pin, int value)
          Set the pulse duration (in microseconds) that causes a servo to rotate to its upper limit.
 void servoSetMinPulseTime(int pin, int value)
          Set the pulse duration (in microseconds) that causes a servo to rotate to its lower limit.
 void servoWrite(int pin, int value)
          Write a servo angle to an output pin.
 
Methods inherited from class java.lang.Object
equals, 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

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(PApplet parent,
               java.lang.String iname,
               int irate)
Create a proxy to an Arduino board running the firmata firmware (used with PDuino).

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 (this depends on the firmata version used: 0.1 is at 19200, 0.2 at 115200, 1.0 at 57600)
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)
the - value: 0 being the lowest (always off), and 255 the highest (always on)

servoWrite

public void servoWrite(int pin,
                       int value)
Write a servo angle to an output pin. That pin must have been initialized with servoAttach() before.

Parameters:
pin - the pin to write to (must be 2-13 on arduino)
the - value as an angle: 0 being the minimum, and 180 the maximum

servoAttach

public void servoAttach(int pin)
Initialize servo timer routines on a pin.

Parameters:
pin - the pin to attach the servo to (must be 2-13 on arduino)

servoDetach

public void servoDetach(int pin)
Stop pulse output to a pin.

Parameters:
pin - the pin to detach the servo from (must be 2-13 on arduino)

servoSetMinPulseTime

public void servoSetMinPulseTime(int pin,
                                 int value)
Set the pulse duration (in microseconds) that causes a servo to rotate to its lower limit. Typical value for Futaba/Hi-Tec servos is around 500.

Parameters:
pin - the pin to write to (must be 2-13 on arduino)
value - pulse duration in microseconds

servoSetMaxPulseTime

public void servoSetMaxPulseTime(int pin,
                                 int value)
Set the pulse duration (in microseconds) that causes a servo to rotate to its upper limit. Typical value for Futaba/Hi-Tec servos is around 2500.

Parameters:
pin - the pin to write to (must be 2-13 on arduino)
value - pulse duration in microseconds