kopia lustrzana https://github.com/pimoroni/pimoroni-pico
Added offset parameter to Analog, and fixed it not switching between ADC pins
rodzic
41d55b1115
commit
1b79e85be7
|
@ -2,11 +2,14 @@
|
|||
|
||||
namespace pimoroni {
|
||||
uint16_t Analog::read_raw() {
|
||||
adc_select_input(pin - 26);
|
||||
return adc_read();
|
||||
}
|
||||
|
||||
float Analog::read_voltage() {
|
||||
return ((float)adc_read() * 3.3f) / (1 << 12) / amplifier_gain;
|
||||
adc_select_input(pin - 26);
|
||||
float voltage = ((((float)adc_read() * 3.3f) / (1 << 12)) + offset) / amplifier_gain;
|
||||
return MAX(voltage, 0.0f);
|
||||
}
|
||||
|
||||
float Analog::read_current() {
|
||||
|
|
|
@ -9,8 +9,8 @@ namespace pimoroni {
|
|||
|
||||
class Analog {
|
||||
public:
|
||||
Analog(uint pin, float amplifier_gain = 1.0f, float resistor = 0.0f) :
|
||||
pin(pin), amplifier_gain(amplifier_gain), resistor(resistor) {
|
||||
Analog(uint pin, float amplifier_gain = 1.0f, float resistor = 0.0f, float offset = 0.0f) :
|
||||
pin(pin), amplifier_gain(amplifier_gain), resistor(resistor), offset(offset) {
|
||||
adc_init();
|
||||
|
||||
//Make sure GPIO is high-impedance, no pullups etc
|
||||
|
@ -26,6 +26,7 @@ namespace pimoroni {
|
|||
uint pin;
|
||||
float amplifier_gain;
|
||||
float resistor;
|
||||
float offset;
|
||||
};
|
||||
|
||||
}
|
Ładowanie…
Reference in New Issue