3 The following shows ADC module APIs available for each platform.
5 | | Linux<br/>(Ubuntu) | Raspbian<br/>(Raspberry Pi) | Nuttx<br/>(STM32F4-Discovery) |
6 | :---: | :---: | :---: | :---: |
7 | adc.open | O | O | O |
8 | adcpin.read | O | O | O |
9 | adcpin.readSync | O | O | O |
10 | adcpin.close | O | O | O |
11 | adcpin.closeSync | O | O | O |
17 * [Constructor](#adc-constructor)
18 * [`new ADC()`](#adc-new)
19 * [Prototype methods](#adc-prototype-methods)
20 * [`adc.open(configuration[, callback])`](#adc-open)
22 * [Prototype methods](#adcpin-prototype-methods)
23 * [`adcpin.read([callback])`](#adcpin-read)
24 * [`adcpin.readSync()`](#adcpin-read-sync)
25 * [`adcpin.close([callback])`](#adcpin-close)
26 * [`adcpin.closeSync()`](#adcpin-close-sync)
28 ## `pin` <a name="pin"></a>
29 On Nuttx, you have to know pin number that is defined in target board module. For more module information, please see below list.
30 * [STM32F4-discovery](../../targets/nuttx-stm32f4/Stm32f4dis.md#adc-pin)
32 ## Class: ADC <a name="adc"></a>
35 ## Constructor <a name="adc-constructor"></a>
38 ### `new ADC()` <a name="adc-new"></a>
40 Returns a new ADC object which can open ADC pin.
43 ## Prototype methods <a name="adc-prototype-methods"></a>
46 ### `adc.open(configuration[, callback])` <a name="adc-open"></a>
47 * `configuration <Object>`
48 * `device <String>`, mandatory configuration on Linux
49 * `pin <Number>`, mandatory configuration on Nuttx
50 * `callback <Function(err: Error | null)>`
53 Opens ADC pin with the specified configuration.
57 var Adc = require('adc');
60 device: '/sys/devices/12d10000.adc/iio:device0/in_voltage0_raw'
69 ## Class: ADCPin <a name="adcpin"></a>
72 ## Prototype methods <a name="adcpin-prototype-methods"></a>
75 ### `adcpin.read([callback])` <a name="adcpin-read"></a>
76 * `callback <Function(err: Error | null, value: Number)>`
78 Reads the analog value from pin asynchronously.
80 `callback` will be called after read the analog value.
84 adc0.read(function(err, value) {
88 console.log('value:', value);
93 ### `adcpin.readSync()` <a name="adcpin-read-sync"></a>
94 * Return: `<Number>`, analog value
96 Reads the analog value from pin synchronously.
100 var value = adc0.readSync();
101 console.log('value:', value);
105 ### `adcpin.close([callback])` <a name="adcpin-close"></a>
106 * `callback <Function(err: Error | null)>`
108 Closes ADC pin asynchronously. This function must be called after the work of ADC finished.
110 `callback` will be called after ADC device is released.
114 adc0.clsoe(function(err) {
122 ### `adcpin.closeSync()` <a name="adcpin-close-sync"></a>
124 Closes ADC pin synchronously. This function must be called after the work of ADC finished.
129 console.log('adc pin is closed');