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