[tm1637] Add set_brightness method (#15322)

Co-authored-by: J. Nick Koston <nick@koston.org>
This commit is contained in:
guillempages
2026-04-16 15:46:27 +02:00
committed by GitHub
parent 04a58159d0
commit ee70a4aa72
2 changed files with 10 additions and 0 deletions

View File

@@ -347,6 +347,13 @@ uint8_t TM1637Display::print(uint8_t start_pos, const char *str) {
}
return pos - start_pos;
}
void TM1637Display::set_brightness(float brightness) {
auto intensity = clamp(brightness, 0.f, 1.f) * 7;
this->set_on(intensity > 0);
this->set_intensity(intensity);
}
uint8_t TM1637Display::print(const char *str) { return this->print(0, str); }
void TM1637Display::set_buffer(const uint8_t *data, uint8_t length) {

View File

@@ -50,6 +50,9 @@ class TM1637Display : public PollingComponent {
/// Set raw buffer bytes from data array up to length bytes.
void set_buffer(const uint8_t *data, uint8_t length);
/// Set the display brightness. Accepts a value between 0.0 and 1.0; 0 will turn off
/// the display and 1.0 will set it to the maximum brightness.
void set_brightness(float brightness);
void set_intensity(uint8_t intensity) { this->intensity_ = intensity; }
void set_inverted(bool inverted) { this->inverted_ = inverted; }
void set_length(uint8_t length) { this->length_ = length; }