|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
public interface CapSense
A pin used for capacitive sensing.
A cap-sense input pin can be used to measure capacitance, most frequently for touch sensing.
CapSense instances are obtained by calling IOIO.openCapSense(int).
Capacitance is measured by pushing a known amount of charge into the circuit, and measuring the increase in voltage. As capacitance gets bigger, this increase becomes smaller, and thus less accurate. As capacitance gets smaller, the increase may become fast enough so it can saturate, i.e. reach the maximum voltage. The system has been tuned to effectively sense capacitance values typical of the human body, for touch sensors. The lowest possible capacitance is about 27pF, and at about 2700pF the precision will be around 10% (with high noise level unless filtered). The internal capacitance of the system with some parasitic capacitance will normally be 30pF or more. Human-body capacitance will typically be about 150pF without grounding, and greater with grounding or when touching a large metallic surface.
Floating-point values in pico-Farade units can be obtained by calling read().
For better noise immunity, some low-pass filtering is recommended. This module provides a simple,
single-pole IIR filtering, with configurable time- constant. There is a trade-off when selecting
the time-constant: a longer time constant will provide better noise filtering, but at the cost of
a slower response. In other words, it will take more time for the measured value to reach the
actual. The default value of DEFAULT_COEF( 25.0fpF) is a reasonable one
in many cases. To change it, call setFilterCoef(float), or use the overload the open
method, which gets a filter coefficient argument: IOIO.openCapSense(int, float).
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:
CapSense touchSensor = ioio.openCapSense(40);
if (touchSensor.read() > 50) {
// Clicked!
...
}
...
touchSensor.close(); // optional. pin 40 can now be used for something else.
IOIO.openCapSense(int),
IOIO.openCapSense(int, float)| Field Summary | |
|---|---|
static float |
DEFAULT_COEF
|
| Method Summary | |
|---|---|
float |
read()
Gets the capacitance reading. |
float |
readSync()
This is very similar to read(), but will wait for a new sample to arrive before
returning. |
void |
setFilterCoef(float t)
Sets the low-pass filter coefficient. |
void |
waitOver(float threshold)
Block until sensed capacitance becomes greater than a given threshold. |
void |
waitOverSync(float threshold)
This is very similar to #waitOver(), but will wait for a new sample to arrive before
returning. |
void |
waitUnder(float threshold)
Block until sensed capacitance becomes less than a given threshold. |
void |
waitUnderSync(float threshold)
This is very similar to #waitUnder(), but will wait for a new sample to arrive before
returning. |
| Methods inherited from interface ioio.lib.api.Closeable |
|---|
close |
| Field Detail |
|---|
static final float DEFAULT_COEF
| Method Detail |
|---|
float read()
throws java.lang.InterruptedException,
ConnectionLostException
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.
This value is computed using a filtered signal, which is configured via
setFilterCoef(float)
java.lang.InterruptedException - The calling thread has been interrupted.
ConnectionLostException - The connection with the IOIO is lost.
float readSync()
throws java.lang.InterruptedException,
ConnectionLostException
read(), but will wait for a new sample to arrive before
returning. This is useful in conjunction with IOIO.sync(), in cases when we want to
guarantee the we are looking at a sample that has been captured strictly after certain other
commands have been executed.
java.lang.InterruptedException - The calling thread has been interrupted.
ConnectionLostException - The connection with the IOIO is lost.read()
void setFilterCoef(float t)
throws ConnectionLostException
t - The time constant, in milliseconds.
ConnectionLostException - The connection with the IOIO is lost.
void waitOver(float threshold)
throws ConnectionLostException,
java.lang.InterruptedException
threshold - The threshold value, in pF units.
ConnectionLostException - The connection with the IOIO is lost.
java.lang.InterruptedException - The calling thread has been interrupted.
void waitOverSync(float threshold)
throws ConnectionLostException,
java.lang.InterruptedException
#waitOver(), but will wait for a new sample to arrive before
returning. This is useful in conjunction with IOIO.sync(), in cases when we want to
guarantee the we are looking at a sample that has been captured strictly after certain other
commands have been executed.
java.lang.InterruptedException - The calling thread has been interrupted.
ConnectionLostException - The connection with the IOIO is lost.#waitOver()
void waitUnder(float threshold)
throws ConnectionLostException,
java.lang.InterruptedException
threshold - The threshold value, in pF units.
ConnectionLostException - The connection with the IOIO is lost.
java.lang.InterruptedException - The calling thread has been interrupted.
void waitUnderSync(float threshold)
throws ConnectionLostException,
java.lang.InterruptedException
#waitUnder(), but will wait for a new sample to arrive before
returning. This is useful in conjunction with IOIO.sync(), in cases when we want to
guarantee the we are looking at a sample that has been captured strictly after certain other
commands have been executed.
java.lang.InterruptedException - The calling thread has been interrupted.
ConnectionLostException - The connection with the IOIO is lost.#waitUnder()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||