ShadowNode

Use Node.js in your end devices(QQ: 796448809)

View the Project on GitHub yodaos-project/ShadowNode

Platform Support

The following table shows ADC module APIs available for each platform.

  Linux
(Ubuntu)
Raspbian
(Raspberry Pi)
NuttX
(STM32F4-Discovery)
TizenRT
(Artik053)
adc.open O X O O
adcpin.read O X O O
adcpin.readSync O X O O
adcpin.close O X O O
adcpin.closeSync O X O O

Class: ADC

This class allows reading analogue data from hardware pins.

The hardware pins can be read from or written to, therefore they are called bidirectional IO pins. This module provides the reading part.

On NuttX, you have to know the number of pins that is defined on the target board module. For more information, please see the list below.

new ADC(configuration[, callback])

Opens an ADC pin with the specified configuration.

Example

var Adc = require('adc');
var adc0 = new Adc({
  device: '/sys/devices/12d10000.adc/iio:device0/in_voltage0_raw'
}, function(err) {
  if (err) {
    throw err;
  }
});

adc.read(callback)

Reads the analog value from the pin asynchronously.

callback will be called having read the analog value.

Example

adc0.read(function(err, value) {
  if (err) {
    throw err;
  }
  console.log('value:', value);
});

adc.readSync()

Reads the analog value from the pin synchronously.

Example

var value = adc0.readSync();
console.log('value:', value);

adc.close([callback])

Closes ADC pin asynchronously. This function must be called after the work of ADC finished.

callback will be called after ADC device is released.

Example

adc0.close(function(err) {
  if (err) {
    throw err;
  }
});

adc.closeSync()

Closes ADC pin synchronously. This function must be called after the work of ADC finished.

Example

adc0.closeSync();
console.log('adc pin is closed');