Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

setBrightness : enhancement #19

Open
stef-ladefense opened this issue Jul 31, 2022 · 4 comments
Open

setBrightness : enhancement #19

stef-ladefense opened this issue Jul 31, 2022 · 4 comments
Labels
enhancement New feature or request

Comments

@stef-ladefense
Copy link
Contributor

I noticed that in the code, when you change the brightness or simply turn off the display, you have to do a setBrightness followed by rewriting the message.
It's counterproductive.
If for example I want to flash the display, at worst I have to do either:

for (uint8_t i = 0; i < 5; i++) {
display.setBrightness(7, false);
display.showNumber(_num, true);
delay(250);
display.setBrightness(7, true);
display.showNumber(_num, true);
delay(250);
}

or better not using setBrightness but rewriting the message all the same

for (uint8_t i = 0; i < 5; i++) {
display.clear();
delay(250);
display.showNumber(_num, true);
delay(250);
}

By simply moving the writing of the TM1637_I2C_COMM3 into the setBrightness, the command becomes instantaneous and allows the brightness to be varied or the display to be turned off or on without rewriting a message after the setBrightness.
this command doesn't need anything else to work.

display.showNumber(_num, true);
for (uint8_t i = 0; i < 5; i++) {
display.setBrightness(7, false);
delay(250) ;
display.setBrightness(7, true);
delay(250) ;
}

change in TM1637TinyDisplay.cpp

void TM1637TinyDisplay::setBrightness(uint8_t brightness, bool on)
{
  m_brightness = (brightness & 0x07) | (on? 0x08 : 0x00);
  
  start();
  writeByte(TM1637_I2C_COMM3 + (m_brightness & 0x0f));
  stop();
}


void TM1637TinyDisplay::setSegments(const uint8_t segments[], uint8_t length, uint8_t pos)
{
...
  // Write COMM3 + brightness
  //start();
  //writeByte(TM1637_I2C_COMM3 + (m_brightness & 0x0f));
  //stop();
}

tested on my current project and works without any observed side effects.
What do you think ?

Stephane

@jasonacox
Copy link
Owner

I love it! ❤️ You are absolutely right. This is more intuitive.

Do you want to submit a pull request with your changes? I can make the change myself but would prefer if you get the credit.

@stef-ladefense
Copy link
Contributor Author

thank ❤
voila !

@jasonacox
Copy link
Owner

Thank you! This is a great upgrade! This will be part of release v1.6.0, coming soon.

jasonacox added a commit that referenced this issue Aug 1, 2022
@jasonacox
Copy link
Owner

v1.6.0 Released: https://www.arduino.cc/reference/en/libraries/tm1637tinydisplay/

You code is now live. Thanks for your contribution and help!

@jasonacox jasonacox added the enhancement New feature or request label Aug 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants