Skip to content

Commit

Permalink
Add support for showing/hiding the colon
Browse files Browse the repository at this point in the history
Allow showing or hiding the colon separator via a lambda call.
Also update the README
  • Loading branch information
guillempages committed Nov 11, 2023
1 parent a3cc01f commit b091405
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
12 changes: 10 additions & 2 deletions components/ht16k33_alpha/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# HT16K33 4 character alphanumeric display
# HT16K33 4 character display

This component supports both the 4 character 14 segment alphanumeric display and the 4 character (plus colon) 7 segment character display. Use the `type` parameter to select which kind of display you have.

There are no print functions for addressing rows and columns. With such a small display I didn't see any point.
All the print functions without the row and column parameters are available.
Expand All @@ -7,14 +9,17 @@ All the same parameters for the i2c display can be used other than the dimension
There are also lambda functions `get_brightness` and `set_brightness` for adjusting the brightness of the display.
You can extend the display across multiple units.

For the 7-segment displays with colon, there is also the `show_colon` lambda function, that can be used to select whether the colon between the second and third digits should be lit or not.

Example:
```yaml
i2c:
i2c:
sda: D0
scl: D1

display:
- platform: ht16k33_alpha
type: alpha
address: 0x70
scroll: true
scroll_speed: 250ms
Expand All @@ -25,6 +30,9 @@ display:
secondary_displays:
- address: 0x71
```
# Required parameters
`type:` choose between `alpha` or `7segment`, depending on which kind of display you have

# Optional parameters

Expand Down
9 changes: 4 additions & 5 deletions components/ht16k33_alpha/ht16k33_display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,11 @@ void HT16K337SegmentDisplay::display_() {
constexpr uint8_t size = 10;
uint8_t buffer[size];
memcpy(buffer, this->buffer_ + offset, 4);
// TODO: implement method to show/hide colon symbol
// if (this->show_colon()) {
// buffer[4] = 0x02;
// } else {
if (this->show_colon_) {
buffer[4] = 0x02;
} else {
buffer[4] = 0;
// }
}
buffer[5] = 0;
memcpy(buffer + 6, this->buffer_ + offset + 4, 4);

Expand Down
3 changes: 3 additions & 0 deletions components/ht16k33_alpha/ht16k33_display.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ class HT16K33BaseDisplay : public PollingComponent, public i2c::I2CDevice {
void strftime(const char *format, ESPTime time) __attribute__((format(strftime, 2, 0)));
#endif

void show_colon(bool show) { this->show_colon_ = show; }

protected:
void command_(uint8_t value);
void call_writer() { this->writer_(*this); }
Expand All @@ -58,6 +60,7 @@ class HT16K33BaseDisplay : public PollingComponent, public i2c::I2CDevice {
int buffer_fill_ {0};
int offset_ {0};
uint8_t brightness_ = 16;
bool show_colon_ {false};
};

class HT16K33AlphaDisplay : public HT16K33BaseDisplay {
Expand Down

0 comments on commit b091405

Please sign in to comment.