SensESP 3.6.1-alpha
Universal Signal K sensor toolkit ESP32
Loading...
Searching...
No Matches
sensesp::ESP32AnalogReader Class Reference

Calibrated analog reader for the ESP32 family. More...

#include <sensesp/sensors/analog_reader.h>

Inheritance diagram for sensesp::ESP32AnalogReader:
[legend]

Public Member Functions

 ESP32AnalogReader (int pin, float max_voltage=kDefaultMaxVoltage)
 
float read () override
 Read the input as a fraction of the full-scale reference voltage.
 
- Public Member Functions inherited from sensesp::BaseAnalogReader
virtual ~BaseAnalogReader ()=default
 

Static Public Attributes

static constexpr float kDefaultMaxVoltage = 3300.
 The nominal 3.3 V supply voltage, in millivolts.
 

Protected Attributes

int pin_
 
float max_voltage_
 

Detailed Description

Calibrated analog reader for the ESP32 family.

Reads the pin using the Arduino core's analogReadMilliVolts(), which applies the ESP-IDF factory ADC calibration, and normalizes the result against a reference voltage.

Definition at line 36 of file analog_reader.h.

Constructor & Destructor Documentation

◆ ESP32AnalogReader()

sensesp::ESP32AnalogReader::ESP32AnalogReader ( int  pin,
float  max_voltage = kDefaultMaxVoltage 
)
inline
Parameters
pinThe GPIO pin to read.
max_voltageThe full-scale reference voltage, in millivolts. Must be positive and finite; any other value would make read() return a meaningless fraction, so it is rejected in favour of the default.

Definition at line 53 of file analog_reader.h.

Member Function Documentation

◆ read()

float sensesp::ESP32AnalogReader::read ( )
inlineoverridevirtual

Read the input as a fraction of the full-scale reference voltage.

Returns
A value in the range 0..1, where 1.0 corresponds to the reader's full-scale reference voltage. Normalizing here keeps AnalogInput independent of the ADC bit width, which varies between ESP32 variants.

Implements sensesp::BaseAnalogReader.

Definition at line 63 of file analog_reader.h.

Member Data Documentation

◆ kDefaultMaxVoltage

constexpr float sensesp::ESP32AnalogReader::kDefaultMaxVoltage = 3300.
staticconstexpr

The nominal 3.3 V supply voltage, in millivolts.

Definition at line 39 of file analog_reader.h.

◆ max_voltage_

float sensesp::ESP32AnalogReader::max_voltage_
protected

Definition at line 43 of file analog_reader.h.

◆ pin_

int sensesp::ESP32AnalogReader::pin_
protected

Definition at line 42 of file analog_reader.h.


The documentation for this class was generated from the following file: