|
| | AnalogInput (uint8_t pin=A0, unsigned int read_delay=200, const String &config_path="", float output_scale=1024.) |
| |
| virtual | ~AnalogInput () |
| |
| virtual bool | to_json (JsonObject &root) override |
| |
| virtual bool | from_json (const JsonObject &config) override |
| |
| | Sensor (String config_path) |
| |
| | SensorConfig (const String &config_path) |
| |
| | Observable () |
| |
| | Observable (Observable &&other) |
| | Move constructor.
|
| |
| void | notify () |
| |
| int | attach (std::function< void()> observer) |
| | Attach an observer callback.
|
| |
| void | detach (int id) |
| | Remove a previously attached observer by its ID.
|
| |
| | FileSystemSaveable (const String &config_path) |
| |
| virtual bool | load () override |
| | Load and populate the object from a persistent storage.
|
| |
| virtual bool | save () override |
| | Save the object to a persistent storage.
|
| |
| virtual bool | clear () override |
| | Delete the data from a persistent storage.
|
| |
| bool | find_config_file (const String &config_path, String &filename) |
| |
| | Saveable (const String &config_path) |
| |
| virtual bool | refresh () |
| | Refresh the object. This may or may not access the persistent storage but is not expected to overwrite the object's state.
|
| |
| const String & | get_config_path () const |
| |
| | ValueProducer () |
| |
| | ValueProducer (const T &initial_value) |
| |
| virtual const T & | get () const |
| |
| template<typename VConsumer > |
| std::enable_if< std::is_base_of< ValueConsumer< typenameVConsumer::input_type >, VConsumer >::value &&std::is_convertible< T, typenameVConsumer::input_type >::value, std::shared_ptr< VConsumer > >::type | connect_to (std::shared_ptr< VConsumer > consumer) |
| | Connect a producer to a transform with a different input type.
|
| |
| template<typename VConsumer > |
| std::enable_if< std::is_base_of< ValueConsumer< typenameVConsumer::input_type >, VConsumer >::value &&std::is_convertible< T, typenameVConsumer::input_type >::value, VConsumer * >::type | connect_to (VConsumer *consumer) |
| |
| template<typename VConsumer > |
| std::enable_if< std::is_base_of< ValueConsumer< typenameVConsumer::input_type >, VConsumer >::value &&std::is_convertible< T, typenameVConsumer::input_type >::value, VConsumer * >::type | connect_to (VConsumer &consumer) |
| |
| void | emit (const T &new_value) |
| |
Sensor for reading the MCU analog input pins.
Read an analog input pin at regular intervals and return the result scaled onto a given range. The reading is calibrated in millivolts using the Arduino core's analogReadMilliVolts(), so it compensates for the ESP32 ADC's nonlinearity. The ADCs are still noisy; for high accuracy, SensESP supports the ADS1015 and ADS1115 ADCs.
Unlike RepeatSensor, AnalogInput can expose its read delay in the web configuration UI. Give it a config_path and pass it to ConfigItem() if you want to adjust the read interval at run time.
- Parameters
-
| [in] | pin | The GPIO pin to read. Which pins are usable depends on the ESP32 variant. Note that pins on ADC2 cannot be read while Wi-Fi is active, which in practice limits you to ADC1 pins (GPIO 32..39 on the original ESP32). |
| [in] | read_delay | Time delay between consecutive readings, in ms |
| [in] | config_path | Configuration path for the sensor |
| [in] | output_scale | The scale of the converted input value that AnalogInput produces. The raw value width of the ADC varies between ESP32 variants, so AnalogInput normalizes the calibrated input voltage against a 3.3 V full-scale reference and multiplies that fraction by 'output_scale'. Output is therefore in the range 0 to 'output_scale', and the same code behaves identically across variants. The default value is 1024. If you want your output expressed as a percentage, make this parameter 100. If you want the actual voltage at the pin, make it 3.3 – that holds regardless of the ADC attenuation set with analogSetAttenuation(), because the reading is calibrated in millivolts before it is scaled. If you want the voltage on the input side of a physical voltage divider, make this parameter the voltage that the divider maps onto the pin's full-scale range. |
Definition at line 48 of file analog_input.h.