hypermedia.pinguino
Class Pinguino

java.lang.Object
  extended by hypermedia.pinguino.Pinguino

public class Pinguino
extends Object

Main object to communicate with Pinguino board via USB port.

You can test all implemented method with this small program.


Field Summary
 int DEFAULT_TIMEOUT
          Default timeout value in milliseconds.
static String errmsg
          The last error message
static int HIGH
          Digital pin status.
static int LOW
           
 
Constructor Summary
Pinguino()
          Create a new Pinguino object and initialize board connection.
Pinguino(PApplet parent)
          Create a new Pinguino object and initialize board connection.
 
Method Summary
 int analogRead(int pin)
          Retrieve the specified analog pin value.
 void analogWrite(int pin, int value)
          Send the given value to the specified analog pin number.
 void clear()
          Clear all pin values.
 int digitalRead(int pin)
          Retrieve the specified digital pin value.
 void digitalWrite(int pin, int value)
          Send the given value to the specified pin number.
 void dispose()
          Clear all pins value and close device connection.
static void log(boolean enable)
          Enable/disable status updates.
This method is static and should be called before creating the Pinguino object.
 byte[] read(byte[] result)
          Retrieve the latest message from Pinguino device with the default timeout value.
 byte[] read(byte[] result, int timeout)
          Retrieve the latest message from Pinguino device with an optional timeout value.
 void write(byte[] data)
          Send the given data to Pinguino device.
 void write(byte[] data, int timeout)
          Send the given data to Pinguino device with an optional timeout value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

HIGH

public static final int HIGH
Digital pin status.

See Also:
Constant Field Values

LOW

public static final int LOW
See Also:
Constant Field Values

DEFAULT_TIMEOUT

public final int DEFAULT_TIMEOUT
Default timeout value in milliseconds.

See Also:
Constant Field Values

errmsg

public static String errmsg
The last error message

Constructor Detail

Pinguino

public Pinguino()
Create a new Pinguino object and initialize board connection.


Pinguino

public Pinguino(PApplet parent)
Create a new Pinguino object and initialize board connection.

Parameters:
parent - the Processing PApplet object (typically use "this")
Method Detail

dispose

public void dispose()
Clear all pins value and close device connection. This method is automatically called by Processing when the PApplet shuts down.


write

public void write(byte[] data)
Send the given data to Pinguino device.

Parameters:
data - data as byte array to be sent
See Also:
write( byte[] ), read( byte[] ), read( byte[], int )

write

public void write(byte[] data,
                  int timeout)
Send the given data to Pinguino device with an optional timeout value.

Parameters:
data - data as byte array to be sent
timeout - amount of time in milliseconds the device will try to send the data
See Also:
write( byte[] ), read( byte[] ), read( byte[], int )

digitalWrite

public void digitalWrite(int pin,
                         int value)
Send the given value to the specified pin number.

Parameters:
pin - the target pin number
value - the new pin value ( 1, HIGH, 0, LOW )
See Also:
HIGH, LOW, analogWrite( int, int )

analogWrite

public void analogWrite(int pin,
                        int value)
Send the given value to the specified analog pin number.

Parameters:
pin - the target pin number
value - the new pin value ( 0 - 1024 )
See Also:
digitalWrite( int, int )

read

public byte[] read(byte[] result)
Retrieve the latest message from Pinguino device with the default timeout value.

Parameters:
result - the data list to be returned
See Also:
read( byte[], int ), write( byte[], int ), write( byte[] )

read

public byte[] read(byte[] result,
                   int timeout)
Retrieve the latest message from Pinguino device with an optional timeout value.

Parameters:
result - the data list to be returned
timeout - amount of time in milliseconds the device will try to give the data
See Also:
read( byte[] ), write( byte[] ), write( byte[], int )

digitalRead

public int digitalRead(int pin)
Retrieve the specified digital pin value.

Parameters:
pin - the pin index
Returns:
int the pin value 0 (LOW) or 1 (HIGH), or -1 on error
See Also:
digitalWrite( int, int ), analogWrite( int, int ), analogRead( int )

analogRead

public int analogRead(int pin)
Retrieve the specified analog pin value.

Parameters:
pin - the pin index
Returns:
int the pin value (0-1024) or -1 on error
See Also:
analogWrite( int, int ), digitalWrite( int, int ), digitalRead( int )

clear

public void clear()
Clear all pin values.


log

public static void log(boolean enable)
Enable/disable status updates.
This method is static and should be called before creating the Pinguino object.

Parameters:
enable - enable/disable status updates, disabled by default