Improved char* format(..) function
I modified the MPGuino for motorcycle use, and I also added a temperature sensor. Next thing I recognised: format() function doesn't support negative values ^^ Of course, they are not needed in original MPGuino.
If somebody also wants to add meters etc that can return negative numbers, here is my improved one. Beyond support of negatives, I changed: .) no leading 0 anymore. I don't like the "005.99" Display, so now it shows " 5.99". .) a second byte parameter gives you control over the amound of post decimal positions. Or, to be more precise, the maxmimum amount you want to be displayed. I don't think it's useful to show the value of a temperatur sensor in "00.00" if it has a precision of +-0.25°C! Also, speed with 2 post decimal positions seems wired to me. Of course you have to modifiy the screen functions to use this. You also may want to create a format function without "maxdec". As I know, Arduino supports overloading funcions, so that shouldn't be a problem. Code:
char* format(long num, byte maxdec){ //gets the *1000 value and max post decimal positions Edit: little code change, there was a bug in it. Someone knows why fBuff has to be initialised as a global variable? I tried to define it in format(), and it messed up the display. |
Hey,
if you define function prototype with default value, then you can call function normally when 2 decimal places is needed: Quote:
|
Quote:
I also have a modified format() in the Code Hacks wiki, that you can play with. It might be a little tighter, I dont know. It doesnt support negative numbers, but does have leading blanks instead of zeros, and has flexible decimal places. It might not be easy to find, as it's only a small part of a huge hack. |
Last night driving home admiring my new device, I was thinking the display could be a tad bigger, now I just realized all I need to do is get rid of the extra numbers!
I haven't got a clue about programming though. |
All times are GMT -4. The time now is 01:26 AM. |
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Content Relevant URLs by vBSEO 3.5.2
All content copyright EcoModder.com