public class ADC
extends java.lang.Object
An ADC channel allows you to read ADC samples from a physical board or module pin.
To obtain an instance of one ADC channel you have to use the
ADCManager.createADC(int)
method.
ADCManager
Modifier and Type | Method and Description |
---|---|
int |
getChannel()
Returns the channel number of this ADC.
|
int |
getValue()
Returns the current ADC channel value.
|
void |
registerListener(IADCListener listener)
Registers the given listener to periodically receive ADC samples.
|
void |
startSampling(int samplingRate)
Starts reading samples with the specified sampling rate.
|
void |
stopSampling()
Stops the sampling process.
|
void |
unregisterListener(IADCListener listener)
Unregisters the given listener to stop receiving ADC channel samples.
|
public int getChannel()
public int getValue() throws java.io.IOException
java.io.IOException
- If there is an error reading the ADC value.public void registerListener(IADCListener listener)
If the given listener is already registered, this method does nothing.
The listener will start receiving samples as soon as the
startSampling(int)
method is called. No more samples will be
received after calling stopSampling()
method.
listener
- The listener to be registered.java.lang.NullPointerException
- If listener == null
.startSampling(int)
,
stopSampling()
,
unregisterListener(IADCListener)
public void unregisterListener(IADCListener listener)
If the given listener is not registered, this method does nothing.
listener
- The listener to be unregistered.java.lang.NullPointerException
- If listener == null
.registerListener(IADCListener)
,
startSampling(int)
,
stopSampling()
public void startSampling(int samplingRate)
Samples are read until the process is stopped using the
stopSampling()
method. The read samples are notified to the
registered listeners.
It does nothing if the channel process is already running.
samplingRate
- Time in milliseconds between samples.java.lang.IllegalArgumentException
- If sampling <= 0
.registerListener(IADCListener)
,
stopSampling()
,
unregisterListener(IADCListener)
public void stopSampling()
It does nothing if the sampling process is not running.