Permalink
Browse files

ISSUE #20: Support for negative decimal numbers

  • Loading branch information...
rjbatista committed Feb 20, 2012
1 parent 82e0b24 commit 93f466272437fb6c60e6c7fc0adbbcbd3e5d741f
Showing with 32 additions and 3 deletions.
  1. +1 −0 CHANGES.txt
  2. +24 −3 TM1638.cpp
  3. +5 −0 TM1638.h
  4. +2 −0 TM16XXFonts.h
@@ -1,3 +1,4 @@
- ISSUE #20: Support for negative decimal numbers;
- ISSUE #19: Corrected setDisplayToString dot bug.
Version 2.0.1
@@ -44,18 +44,18 @@ void TM1638::setDisplayToHexNumber(unsigned long number, byte dots, boolean lead
}
}
void TM1638::setDisplayToDecNumber(unsigned long number, byte dots, boolean leadingZeros,
void TM1638::setDisplayToDecNumberAt(unsigned long number, byte dots, byte startingPos, boolean leadingZeros,
const byte numberFont[])
{
if (number > 99999999L) {
setDisplayToError();
} else {
for (int i = 0; i < displays; i++) {
for (int i = 0; i < displays - startingPos; i++) {
if (number != 0) {
setDisplayDigit(number % 10, displays - i - 1, (dots & (1 << i)) != 0, numberFont);
number /= 10;
} else {
if (leadingZeros) {
if (leadingZeros) {
setDisplayDigit(0, displays - i - 1, (dots & (1 << i)) != 0, numberFont);
} else {
clearDisplayDigit(displays - i - 1, (dots & (1 << i)) != 0);
@@ -65,6 +65,27 @@ void TM1638::setDisplayToDecNumber(unsigned long number, byte dots, boolean lead
}
}
void TM1638::setDisplayToDecNumber(unsigned long number, byte dots, boolean leadingZeros,
const byte numberFont[])
{
setDisplayToDecNumberAt(number, dots, leadingZeros, 0, numberFont);
}
void TM1638::setDisplayToSignedDecNumber(signed long number, byte dots, boolean leadingZeros,
const byte numberFont[])
{
if (number >= 0) {
setDisplayToDecNumberAt(number, dots, 0, leadingZeros, numberFont);
} else {
if (-number > 9999999L) {
setDisplayToError();
} else {
setDisplayToDecNumberAt(-number, dots, 1, leadingZeros, numberFont);
sendChar(0, MINUS, (dots & (0x80)) != 0);
}
}
}
void TM1638::setDisplayToBinNumber(byte number, byte dots, const byte numberFont[])
{
for (int i = 0; i < displays; i++) {
@@ -43,6 +43,9 @@ class TM1638 : public TM16XX
/** Set the display to a unsigned decimal number (with or without leading zeros) */
void setDisplayToDecNumber(unsigned long number, byte dots, boolean leadingZeros = true,
const byte numberFont[] = NUMBER_FONT);
/** Set the display to a signed decimal number (with or without leading zeros) */
void setDisplayToSignedDecNumber(signed long number, byte dots, boolean leadingZeros = true,
const byte numberFont[] = NUMBER_FONT);
/** Set the display to a unsigned binary number */
void setDisplayToBinNumber(byte number, byte dots,
const byte numberFont[] = NUMBER_FONT);
@@ -57,6 +60,8 @@ class TM1638 : public TM16XX
protected:
virtual void sendChar(byte pos, byte data, boolean dot);
void setDisplayToDecNumberAt(unsigned long number, byte dots, byte startingPos,
boolean leadingZeros, const byte numberFont[]);
};
#endif
@@ -50,6 +50,8 @@ const byte NUMBER_FONT[] = {
0b01110001 // F
};
const byte MINUS = 0b01000000;
// definition for error
const byte ERROR_DATA[] = {
0b01111001, // E

0 comments on commit 93f4662

Please sign in to comment.