ESPHome 2026.6.0-dev
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::sm16716 {
5
6static const char *const TAG = "sm16716";
7
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}
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}
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
virtual void setup()=0
virtual void digital_write(bool value)=0
void dump_config() override
Definition sm16716.cpp:15
std::vector< uint8_t > pwm_amounts_
Definition sm16716.h:66
void write_byte_(uint8_t data)
Definition sm16716.h:56
void loop() override
Send new values if they were updated.
Definition sm16716.cpp:24
void write_bit_(bool value)
Definition sm16716.h:51
void setup() override
Definition sm16716.cpp:8