ADC

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

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');
});
}

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.
'use strict';

var driver = require('ruff-driver');

module.exports = driver({
attach: function (inputs) {
this._adc = inputs['adc'];
},

exports: {
getInputVoltage: function (callback) {
this._adc.getVoltage(function (error, voltage) {
if (error) {
callback(error);
return;
}

callback(undefined, voltage + 'v');
});
}
}
});