RobTillaart / HT16K33

Arduino Library for HT16K33 4x7segment display
MIT License
24 stars 6 forks source link

Add support for displayFixedPoint() ? #11

Closed RobTillaart closed 3 years ago

RobTillaart commented 4 years ago

displayFixedPoint(float f, uint8_t pos) Display a float in a fixed point float format e.g. always one decimal.

This improves the readability of the numbers as it is less error prone than reading with a floating point position. Special care has to be taken for negative numbers as these would shift the position of the point by one place... how bad is this? Keeping the point in the same spot would mean that one must keep one position free for sign, so only 3 digit positions are available. implying only #.## or ##.# or ### pattern is possible

RobTillaart commented 3 years ago

If there was another way to do negative numbers e.g. also set the last decimal . or the : in the middle, but non of those are common as far as I know.

if only positive numbers need to be supported one could do


int displayFixedPoint(float f, uint8_t pos)
{
  if (f < 0) return UNDERFLOW_ERROR;
  if ((pos == 1) && (f >= 10)) return OVERFLOW_ERROR;
  if ((pos == 2) && (f >= 100)) return OVERFLOW_ERROR;
  if ((pos == 3) && (f >= 1000)) return OVERFLOW_ERROR;
  // data OK -> display it.
  ....
  return OK;
}

However the user needs to verify the return value explicitly every time..

RobTillaart commented 3 years ago

What are the ranges needed?
I need applications to get more clear requirements.

RobTillaart commented 3 years ago

Closed as displayFixedPointX() makes these possible.