ESPHome  2024.11.0
mcp3008_sensor.cpp
Go to the documentation of this file.
1 #include "mcp3008_sensor.h"
2 
3 #include "esphome/core/log.h"
4 
5 namespace esphome {
6 namespace mcp3008 {
7 
8 static const char *const TAG = "mcp3008.sensor";
9 
11 
13  ESP_LOGCONFIG(TAG, "MCP3008Sensor:");
14  ESP_LOGCONFIG(TAG, " Pin: %u", this->pin_);
15  ESP_LOGCONFIG(TAG, " Reference Voltage: %.2fV", this->reference_voltage_);
16 }
17 
19  float value_v = this->parent_->read_data(pin_);
20  value_v = (value_v * this->reference_voltage_);
21  return value_v;
22 }
23 
24 void MCP3008Sensor::update() { this->publish_state(this->sample()); }
25 
26 } // namespace mcp3008
27 } // namespace esphome
const float DATA
For components that import data from directly connected sensors like DHT.
Definition: component.cpp:19
float get_setup_priority() const override
void publish_state(float state)
Publish a new state to the front-end.
Definition: sensor.cpp:39
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7