upm  1.2.0
Sensor/Actuator repository for libmraa (v1.6.1)
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Public Member Functions
VDiv Class Reference

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 = new upm::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;
sleep(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: