public class Arduino
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
class |
Arduino.FirmataWriter |
class |
Arduino.SerialProxy |
Modifier and Type | Field and Description |
---|---|
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 |
INPUT_PULLUP
Constant to set a pin to input mode and enable the pull-up resistor (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 and Description |
---|
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.
|
Modifier and Type | Method and Description |
---|---|
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.
|
public static final int INPUT
public static final int OUTPUT
public static final int ANALOG
public static final int PWM
public static final int SERVO
public static final int SHIFT
public static final int I2C
public static final int INPUT_PULLUP
public static final int LOW
public static final int HIGH
public Arduino(processing.core.PApplet parent, java.lang.String iname)
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())public Arduino(processing.core.PApplet parent, java.lang.String iname, int irate)
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)public void dispose()
public static java.lang.String[] list()
public int digitalRead(int pin)
pin
- the digital pin whose value should be returned (from 2 to 13,
since pins 0 and 1 are used for serial communication)public int analogRead(int pin)
pin
- the analog pin whose value should be returned (from 0 to 5)public void pinMode(int pin, int mode)
pin
- the pin whose mode to set (from 2 to 13)mode
- either Arduino.INPUT or Arduino.OUTPUTpublic void digitalWrite(int pin, int value)
pin
- the pin to write to (from 2 to 13)value
- the value to write: Arduino.LOW (0 volts) or Arduino.HIGH
(5 volts)public void analogWrite(int pin, int value)
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)public void servoWrite(int pin, int value)
pin
- the pin the servo is attached tovalue
- the value: 0 being the lowest angle, and 180 the highest angle