You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
652 B
34 lines
652 B
3 years ago
|
#include <Arduino.h>
|
||
|
|
||
|
struct ADC_CalibrationValue
|
||
|
{
|
||
|
float MeasuredVoltage;
|
||
|
int16_t ADC_Value;
|
||
|
};
|
||
|
|
||
|
// To improve ADC precision, these values must be measured with a voltmeter
|
||
|
// You can use a potentiometer to generate different voltages, measure them, and add an entry with the corresponding ADC value returned by analogRead()
|
||
|
const ADC_CalibrationValue ADC_calibration[] = {
|
||
|
{ 0.118f, 1 },
|
||
|
{ 0.343f, 253 },
|
||
|
{ 0.791f, 801 },
|
||
|
{ 1.512f, 1705 },
|
||
|
{ 2.013f, 2306 },
|
||
|
{ 2.406f, 2796 },
|
||
|
{ 2.606f, 3058 },
|
||
|
{ 2.839f, 3423 },
|
||
|
{ 2.996f, 3726 },
|
||
|
{ 3.16f, 4094 }
|
||
|
};
|
||
|
|
||
|
class ADC
|
||
|
{
|
||
|
public:
|
||
|
ADC(int8_t gpioPin);
|
||
|
|
||
|
float read();
|
||
|
|
||
|
private:
|
||
|
int8_t pin_;
|
||
|
};
|