upm  1.7.1
Sensor/Actuator repository for libmraa (v2.0.0)
Public Member Functions

API for the Voltage Divider Sensor. More...

Detailed Description

UPM module for the Voltage Divider sensor

vdiv.jpg
// Instantiate a Grove Voltage Divider sensor on analog pin A0
upm::VDiv vDiv(0);
// collect data and output measured voltage according to the setting
// of the scaling switch (3 or 10)
while (shouldRun) {
unsigned int val = vDiv.value(100);
float gain3val = vDiv.computedValue(3, val);
float gain10val = vDiv.computedValue(10, val);
cout << "ADC value: " << val << " Gain 3: " << gain3val << "v Gain 10: " << gain10val << "v"
<< endl;
upm_delay(1);
}

Public Member Functions

 VDiv (int pin)
 
 ~VDiv ()
 
unsigned int value (unsigned int samples)
 
float computedValue (uint8_t gain, unsigned int val, int vref=VDIV_VREF, int res=VDIV_ADC_RES)
 

Constructor & Destructor Documentation

VDiv ( int  pin)

Voltage Divider sensor constructor

Parameters
pinAnalog pin to use
~VDiv ( )

Voltage Divider destructor

Member Function Documentation

unsigned int value ( unsigned int  samples)

Gets the conversion value from the sensor

Parameters
samplesSpecifies how many samples to average over
Returns
Average ADC conversion value
float computedValue ( uint8_t  gain,
unsigned int  val,
int  vref = VDIV_VREF,
int  res = VDIV_ADC_RES 
)

Computes the measured voltage

Parameters
gainGain switch, example: either 3 or 10 grove vdiv
valMeasured voltage (from value())
vrefReference voltage in millivolts
resADC resolution
Returns
Measured voltage

The documentation for this class was generated from the following files: