remove duplicate code: function readAdc was used in multiple files, outsourced this to gpio component
22 lines
558 B
C++
22 lines
558 B
C++
#include "gpio_adc.hpp"
|
|
|
|
|
|
//=============================
|
|
//========= readAdc ===========
|
|
//=============================
|
|
//function for multisampling an anlog input
|
|
int gpio_readAdc(adc1_channel_t adc_channel, bool inverted) {
|
|
//make multiple measurements
|
|
int adc_reading = 0;
|
|
for (int i = 0; i < 32; i++) {
|
|
adc_reading += adc1_get_raw(adc_channel);
|
|
}
|
|
adc_reading = adc_reading / 32;
|
|
//return original or inverted result
|
|
if (inverted) {
|
|
return 4095 - adc_reading;
|
|
} else {
|
|
return adc_reading;
|
|
}
|
|
}
|