ESPHome
2026.6.0-dev
Loading...
Searching...
No Matches
esphome
components
sm16716
sm16716.cpp
Go to the documentation of this file.
1
#include "
sm16716.h
"
2
#include "
esphome/core/log.h
"
3
4
namespace
esphome::sm16716
{
5
6
static
const
char
*
const
TAG =
"sm16716"
;
7
8
void
SM16716::setup
() {
9
this->
data_pin_
->
setup
();
10
this->
data_pin_
->
digital_write
(
false
);
11
this->
clock_pin_
->
setup
();
12
this->
clock_pin_
->
digital_write
(
false
);
13
this->
pwm_amounts_
.resize(this->
num_channels_
, 0);
14
}
15
void
SM16716::dump_config
() {
16
ESP_LOGCONFIG(TAG,
17
"SM16716:\n"
18
" Total number of channels: %u\n"
19
" Number of chips: %u"
,
20
this->
num_channels_
, this->
num_chips_
);
21
LOG_PIN(
" Data Pin: "
, this->
data_pin_
);
22
LOG_PIN(
" Clock Pin: "
, this->
clock_pin_
);
23
}
24
void
SM16716::loop
() {
25
if
(!this->
update_
)
26
return
;
27
28
for
(uint8_t i = 0; i < 50; i++) {
29
this->
write_bit_
(
false
);
30
}
31
32
// send 25 bits (1 start bit plus 24 data bits) for each chip
33
for
(uint8_t index = 0; index < this->
num_channels_
; index++) {
34
// send a start bit initially and after every 3 channels
35
if
(index % 3 == 0) {
36
this->
write_bit_
(
true
);
37
}
38
39
this->
write_byte_
(this->
pwm_amounts_
[index]);
40
}
41
42
// send a blank 25 bits to signal the end
43
this->
write_bit_
(
false
);
44
this->
write_byte_
(0);
45
this->
write_byte_
(0);
46
this->
write_byte_
(0);
47
48
this->
update_
=
false
;
49
}
50
51
}
// namespace esphome::sm16716
esphome::GPIOPin::setup
virtual void setup()=0
esphome::GPIOPin::digital_write
virtual void digital_write(bool value)=0
esphome::sm16716::SM16716::update_
bool update_
Definition
sm16716.h:67
esphome::sm16716::SM16716::num_chips_
uint8_t num_chips_
Definition
sm16716.h:65
esphome::sm16716::SM16716::dump_config
void dump_config() override
Definition
sm16716.cpp:15
esphome::sm16716::SM16716::num_channels_
uint8_t num_channels_
Definition
sm16716.h:64
esphome::sm16716::SM16716::pwm_amounts_
std::vector< uint8_t > pwm_amounts_
Definition
sm16716.h:66
esphome::sm16716::SM16716::data_pin_
GPIOPin * data_pin_
Definition
sm16716.h:62
esphome::sm16716::SM16716::write_byte_
void write_byte_(uint8_t data)
Definition
sm16716.h:56
esphome::sm16716::SM16716::loop
void loop() override
Send new values if they were updated.
Definition
sm16716.cpp:24
esphome::sm16716::SM16716::write_bit_
void write_bit_(bool value)
Definition
sm16716.h:51
esphome::sm16716::SM16716::setup
void setup() override
Definition
sm16716.cpp:8
esphome::sm16716::SM16716::clock_pin_
GPIOPin * clock_pin_
Definition
sm16716.h:63
log.h
esphome::sm16716
Definition
sm16716.cpp:4
sm16716.h
Generated by
1.12.0