grove: sliding potentiometer

Signed-off-by: Mihai Tudor Panu <mihai.t.panu@intel.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
This commit is contained in:
Mihai Tudor Panu
2014-11-06 10:24:56 -08:00
committed by Brendan Le Foll
parent b2ffcdd9ea
commit cebc339d91
7 changed files with 215 additions and 0 deletions

View File

@ -160,3 +160,36 @@ float GroveRotary::rel_rad()
{
return GroveRotary::rel_deg() * M_PI / 180.0;
}
//// GroveSlide ////
GroveSlide::GroveSlide(unsigned int pin, float ref_voltage)
{
mraa_init();
m_aio = mraa_aio_init(pin);
m_ref_voltage = ref_voltage;
m_name = "Slide Potentiometer";
}
GroveSlide::~GroveSlide()
{
mraa_aio_close(m_aio);
}
float GroveSlide::raw_value()
{
return (float) mraa_aio_read(m_aio);
}
float GroveSlide::voltage_value()
{
// conversion to Volts
float a = GroveSlide::raw_value();
a = m_ref_voltage * a / 1023.0 ;
return a;
}
float GroveSlide::ref_voltage()
{
return m_ref_voltage;
}

View File

@ -200,4 +200,51 @@ class GroveRotary: public Grove {
static const int m_max_angle = 300;
};
/**
* @brief C++ API for Grove Slide Potentiometer
*
* Very basic UPM module for Grove slide potentiometer on analog,
* returns either raw value or scaled voltage value.
*
* @ingroup grove analog
* @snippet groveslide.cxx Interesting
* @image html groveslide.jpeg
*/
class GroveSlide: public Grove {
public:
/**
* Grove analog slide potentiometer constructor
*
* @param pin number of analog pin to use
*
* @param ref_voltage the reference voltage the board is set to as float, e.g. 3.3 or 5.0 (default)
*/
GroveSlide(unsigned int pin, float ref_voltage = 5.0);
/**
* GroveSlide Destructor
*/
~GroveSlide();
/**
* Get raw value from AIO pin
*
* @return the raw value from the ADC
*/
float raw_value();
/**
* Get the voltage value from the pin
*
* @return the voltage reading based on the reference voltage
*/
float voltage_value();
/**
* Get the board's reference voltage passed on object initialization
*
* @return the reference voltage the class was set for
*/
float ref_voltage();
private:
mraa_aio_context m_aio;
float m_ref_voltage;
};
}