ioio.lib.api
Interface AnalogInput

All Superinterfaces:
Closeable

public interface AnalogInput
extends Closeable

A pin used for analog input.

An analog input pin can be used to measure voltage. AnalogInput instances are obtained by calling IOIO.openAnalogInput(int).

Floating-point values scaled from 0 to 1 can be obtained by calling read(). Absolute voltage levels can be obtained by calling getVoltage().

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:

 AnalogInput potentiometer = ioio.openAnalogInput(40);
 float value = potentiometer.read();
 ...
 potentiometer.close();  // pin 40 can now be used for something else.
 

See Also:
IOIO.openAnalogInput(int)

Method Summary
 float getReference()
          Gets the maximum value against which read() values are scaled.
 float getVoltage()
          Gets the analog input reading, as an absolute voltage in Volt units.
 float read()
          Gets the analog input reading, as a scaled real value between 0 and 1.
 
Methods inherited from interface ioio.lib.api.Closeable
close
 

Method Detail

getVoltage

float getVoltage()
                 throws java.lang.InterruptedException,
                        ConnectionLostException
Gets the analog input reading, as an absolute voltage in Volt units.

It typically takes a few milliseconds between when the instance is created and until the first value can be read. In this case, the method may block shortly. If this is a problem, the calling thread can be interrupted.

If a scaled value is desired, consider using read().

Returns:
The voltage, in Volt units.
Throws:
java.lang.InterruptedException - The calling thread has been interrupted.
ConnectionLostException - The connection with the IOIO is lost.
See Also:
read()

getReference

float getReference()
Gets the maximum value against which read() values are scaled.

Returns:
The voltage, in Volts.

read

float read()
           throws java.lang.InterruptedException,
                  ConnectionLostException
Gets the analog input reading, as a scaled real value between 0 and 1.

It typically takes a few milliseconds between when the instance is created and until the first value can be read. In this case, the method may block shortly. If this is a problem, the calling thread can be interrupted.

If an absolute value is desired, consider using getVoltage().

Returns:
The voltage, in scaled units.
Throws:
java.lang.InterruptedException - The calling thread has been interrupted.
ConnectionLostException - The connection with the IOIO is lost.
See Also:
getVoltage()