valerionew / ht1621-7-seg

arduino library for 7-segment lcd based on ht1621 drivers
Other
19 stars 13 forks source link

There is wrongly displayed value "0" #7

Closed mwwojcik2017 closed 4 years ago

mwwojcik2017 commented 4 years ago

Hi, I am using this library to display seconds - the value is stored in "centiseconds" variable (0.01s). When running command: "lcd.print(centiseconds/100.0, 2);" it is displaying empty space with "." and only the last "0". It looks like leading zeros handling is wrongly designed. I would expect to see "0.00" instead of " . 0" Please check it.

valerionew commented 4 years ago

Hey, i've made a code change in the above linked pr that should fix the issue, but i can't test it at the moment since i don't have the display with me. Can you test it for me?

mwwojcik2017 commented 4 years ago

Hi there, I trust you are OK in this very bad moment... I don't know how to test newest version as the library available in Arduino is still 2.0.1

mwwojcik2017 commented 4 years ago

Of course I can test it immediately if you will share new version with me. Also, it would worth to have a option to write any kind of symbol (like "E" "o" "C" etc.) Thank you,

valerionew commented 4 years ago

Alright, let me help you.

Open your arduino libraries folder, if you're on Windows it's: C:\Users\[your user]\Documents\Arduino\libraries open the HT1621 and go inside the src folder. Open the HT1621.cpp file and replace this line:

snprintf(localbuffer,7, "%6li", num); // convert the decimal into string

With this line:

snprintf(localbuffer,7, "%06li", num); // convert the decimal into string

mwwojcik2017 commented 4 years ago

I did, but I am afraid the issue lies here:

void HT1621::print(float num){ // could be smarter and actually check how many // non zeros we have in the decimals print(num, 3);

valerionew commented 4 years ago

It is not: that function isn't even called if you specify the precision yourself. That function just assumes, if no precision is given, that the precision is 3

mwwojcik2017 commented 4 years ago

OK, I am not so good at programming so I trust you - what I achieved is value displayed with all zeros - 0000.01 and so on. Well, it is much better now, so thank you for the tip. Ideally, it should show only one leading zero.

valerionew commented 4 years ago

Hey @mwwojcik2017 Would you please try this new version of the library to see if this fix the issue?

HT1621.zip