ESPHome
2026.3.0-dev
Loading...
Searching...
No Matches
esphome
components
mcp3008
sensor
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
10
void
MCP3008Sensor::dump_config
() {
11
ESP_LOGCONFIG(TAG,
12
"MCP3008Sensor:\n"
13
" Pin: %u\n"
14
" Reference Voltage: %.2fV"
,
15
this->
pin_
, this->
reference_voltage_
);
16
}
17
18
float
MCP3008Sensor::sample
() {
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
esphome::Parented< MCP3008 >::parent_
MCP3008 * parent_
Definition
helpers.h:1629
esphome::mcp3008::MCP3008Sensor::update
void update() override
Definition
mcp3008_sensor.cpp:24
esphome::mcp3008::MCP3008Sensor::pin_
uint8_t pin_
Definition
mcp3008_sensor.h:25
esphome::mcp3008::MCP3008Sensor::dump_config
void dump_config() override
Definition
mcp3008_sensor.cpp:10
esphome::mcp3008::MCP3008Sensor::sample
float sample() override
Definition
mcp3008_sensor.cpp:18
esphome::mcp3008::MCP3008Sensor::reference_voltage_
float reference_voltage_
Definition
mcp3008_sensor.h:26
esphome::sensor::Sensor::publish_state
void publish_state(float state)
Publish a new state to the front-end.
Definition
sensor.cpp:65
log.h
mcp3008_sensor.h
esphome
Providing packet encoding functions for exchanging data with a remote host.
Definition
a01nyub.cpp:7
Generated by
1.12.0