ADC
Analog-to-Digital converter (ADC), is a common hardware interface and converts analog signal to digital signal.
- please click here for more information.
Prerequisites
- Please click here if you are not sure how to use Ruff to write apps.
- Please click Driver - Getting Started and Driver - Programming Model, if you know nothing about the driver development.
Using ADC
- Please read the datasheet to confirm that the interface is ADC.
Configuring driver.json
Please ensure your interface is ADC in driver.json and declare it as ADC. The declaration should be inputs with type as ADC.{
...
"inputs": {
"adc": {
"type": "adc"
}
}
}
Writing a Driver
The driver can read ADC interface to get the value of voltage that is converted from analog signal based on A/D conversion. An example is listed as follows:function getInputVoltage(callback) {
this._adc.getVoltage(function (error, voltage) {
if (error) {
callback(error);
return;
}
callback(undefined, voltage + 'v');
});
}
- Please visit ADC API document to for more details.
Application
The following example demontrates the process of writing a driver for the module with an ADC interface. You can declare it in driver.json.{
"inputs": {
"adc": {
"type": "adc"
}
}
}
We provide the module with a method:
- getInputVoltage - get voltage and convert it to ~v format.
; |