ioio.lib.api
Interface DigitalInput

All Superinterfaces:
Closeable

public interface DigitalInput
extends Closeable

A pin used for digital input.

A digital input pin can be used to read logic-level signals. DigitalInput instances are obtained by calling IOIO.openDigitalInput(DigitalInput.Spec).

The value of the pin is obtained by calling read(). It is also possible for the client to block until a certain level is sensed, by using waitForValue(boolean).

The instance is alive since its creation. The first read() call block for a few milliseconds until the initial value is updated. If the connection with the IOIO drops at any point, the instance transitions to a disconnected state, in which every attempt to use the pin (except Closeable.close()) will throw a ConnectionLostException. Whenever Closeable.close() is invoked the instance may no longer be used. Any resources associated with it are freed and can be reused.

Typical usage:

 DigitalInput button = ioio.openDigitalInput(10);  // used an external pull-up
 button.waitForValue(false);  // wait for press
 ...
 button.close();  // pin 10 can now be used for something else.
 


Nested Class Summary
static class DigitalInput.Spec
          A digital input pin specification, used when opening digital inputs.
 
Method Summary
 boolean read()
          Read the value sensed on the pin.
 void waitForValue(boolean value)
          Block until a desired logical level is sensed.
 
Methods inherited from interface ioio.lib.api.Closeable
close
 

Method Detail

read

boolean read()
             throws java.lang.InterruptedException,
                    ConnectionLostException
Read the value sensed on the pin. May block for a few milliseconds if called right after creation of the instance. If this is a problem, the calling thread may be interrupted.

Returns:
True for logical "HIGH", false for logical "LOW".
Throws:
java.lang.InterruptedException - The calling thread has been interrupted.
ConnectionLostException - The connection with the IOIO has been lost.

waitForValue

void waitForValue(boolean value)
                  throws java.lang.InterruptedException,
                         ConnectionLostException
Block until a desired logical level is sensed. The calling thread can be interrupted for aborting this operation.

Parameters:
value - The desired logical level. true for "HIGH", false for "LOW".
Throws:
java.lang.InterruptedException - The calling thread has been interrupted.
ConnectionLostException - The connection with the IOIO has been lost.