Skip to content

Commit

Permalink
Add flipDisplay() function #2
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonacox committed May 10, 2022
1 parent 7e94752 commit de6b8f0
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 4 deletions.
8 changes: 8 additions & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,11 @@ display.showAnimation(ANIMATION, FRAMES(ANIMATION), TIME_MS(10));
display.showNumber(9.87, 2, 3, 0);
display.showNumber(1.23, 2, 3, 3);
```

## v1.5.0 (Beta)
- Added support for device orientation, flipping display upside down if selected during
initialization or through a function call (4-Digit in Beta)
```cpp
// Flip display
display.flipDisplay(true);
```
30 changes: 27 additions & 3 deletions TM1637TinyDisplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,14 +161,16 @@ const uint8_t asciiToSegment[] PROGMEM = {
static const uint8_t minusSegments = 0b01000000;
static const uint8_t degreeSegments = 0b01100011;

TM1637TinyDisplay::TM1637TinyDisplay(uint8_t pinClk, uint8_t pinDIO, unsigned int bitDelay, unsigned int scrollDelay)
TM1637TinyDisplay::TM1637TinyDisplay(uint8_t pinClk, uint8_t pinDIO, unsigned int bitDelay, unsigned int scrollDelay, bool flip)
{
// Pin settings
m_pinClk = pinClk;
m_pinDIO = pinDIO;
// Timing configurations
m_bitDelay = bitDelay;
m_scrollDelay = scrollDelay;
// Flip
m_flipDisplay = flip;

// Set the pin direction and default value.
// Both pins are set as inputs, allowing the pull-up resistors to pull them up
Expand All @@ -178,6 +180,11 @@ TM1637TinyDisplay::TM1637TinyDisplay(uint8_t pinClk, uint8_t pinDIO, unsigned in
digitalWrite(m_pinDIO, LOW);
}

void TM1637TinyDisplay::flipDisplay(bool flip)
{
m_flipDisplay = flip;
}

void TM1637TinyDisplay::setBrightness(uint8_t brightness, bool on)
{
m_brightness = (brightness & 0x07) | (on? 0x08 : 0x00);
Expand All @@ -190,18 +197,35 @@ void TM1637TinyDisplay::setScrolldelay(unsigned int scrollDelay)

void TM1637TinyDisplay::setSegments(const uint8_t segments[], uint8_t length, uint8_t pos)
{
uint8_t dot = 0;

// Write COMM1
start();
writeByte(TM1637_I2C_COMM1);
stop();

// Write COMM2 + first digit address
start();
if(m_flipDisplay) pos = MAXDIGITS - pos - length;
writeByte(TM1637_I2C_COMM2 + (pos & 0x07));

// Write the data bytes
for (uint8_t k=0; k < length; k++) {
writeByte(segments[k]);
if(m_flipDisplay) {
for (uint8_t k=0; k < length; k++) {
dot = 0;
if((length - k - 2) >= 0) {
dot = segments[length - k - 2] & 0b10000000;
}
uint8_t orig = segments[length - k - 1];
uint8_t flip = ((orig >> 3) & 0b00000111) +
((orig << 3) & 0b00111000) + (orig & 0b01000000) + dot;
writeByte(flip);
}
}
else {
for (uint8_t k=0; k < length; k++) {
writeByte(segments[k]);
}
}
stop();

Expand Down
1 change: 1 addition & 0 deletions keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ showNumberDec KEYWORD2
showNumberHex KEYWORD2
encodeDigit KEYWORD2
encodeASCII KEYWORD2
flipDisplay KEYWORD2

#######################################
# Constants (LITERAL1)
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=TM1637TinyDisplay
version=1.4.4
version=1.5.0
author=Jason Cox <jason@jasonacox.com>
maintainer=Jason Cox <jason@jasonacox.com>
sentence=A simple library to display numbers, text and animation on 4 and 6 digit 7-segment TM1637 based display modules.
Expand Down

0 comments on commit de6b8f0

Please sign in to comment.