2021-08-18 12:16:51 +01:00
|
|
|
#include "analog.hpp"
|
|
|
|
|
|
|
|
namespace pimoroni {
|
|
|
|
uint16_t Analog::read_raw() {
|
2022-03-25 23:31:27 +00:00
|
|
|
adc_select_input(pin - 26);
|
2021-08-18 12:16:51 +01:00
|
|
|
return adc_read();
|
|
|
|
}
|
|
|
|
|
|
|
|
float Analog::read_voltage() {
|
2022-03-25 23:31:27 +00:00
|
|
|
adc_select_input(pin - 26);
|
|
|
|
float voltage = ((((float)adc_read() * 3.3f) / (1 << 12)) + offset) / amplifier_gain;
|
|
|
|
return MAX(voltage, 0.0f);
|
2021-08-18 12:16:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
float Analog::read_current() {
|
|
|
|
if(resistor > 0.0f)
|
|
|
|
return read_voltage() / resistor;
|
|
|
|
else
|
|
|
|
return read_voltage();
|
|
|
|
}
|
|
|
|
};
|