added support for removing leading zeros in displaying numbers
This commit is contained in:
15
CHANGES.txt
Normal file
15
CHANGES.txt
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
Version 1.3.0
|
||||||
|
|
||||||
|
- added support for removing leading zeros in displaying numbers.
|
||||||
|
|
||||||
|
Version 1.2.0
|
||||||
|
|
||||||
|
- added support for writing text.
|
||||||
|
|
||||||
|
Version 1.1.0
|
||||||
|
|
||||||
|
- restructuring and added 2 proper examples, available in the arduino ide.
|
||||||
|
|
||||||
|
Version 1.0.0
|
||||||
|
|
||||||
|
- initial Release.
|
||||||
23
TM1638.cpp
23
TM1638.cpp
@@ -51,15 +51,19 @@ void TM1638::setupDisplay(boolean active, byte intensity)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void TM1638::setDisplayToHexNumber(unsigned long number, byte dots)
|
void TM1638::setDisplayToHexNumber(unsigned long number, byte dots, boolean leadingZeros)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < 8; i++) {
|
for (int i = 0; i < 8; i++) {
|
||||||
setDisplayDigit(number & 0xF, 7 - i, (dots & (1 << i)) != 0);
|
if (!leadingZeros && number == 0) {
|
||||||
number >>= 4;
|
clearDisplayDigit(7 - i, (dots & (1 << i)) != 0);
|
||||||
|
} else {
|
||||||
|
setDisplayDigit(number & 0xF, 7 - i, (dots & (1 << i)) != 0);
|
||||||
|
number >>= 4;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TM1638::setDisplayToDecNumber(unsigned long number, byte dots)
|
void TM1638::setDisplayToDecNumber(unsigned long number, byte dots, boolean leadingZeros)
|
||||||
{
|
{
|
||||||
if (number > 99999999L) {
|
if (number > 99999999L) {
|
||||||
setDisplay(ERROR);
|
setDisplay(ERROR);
|
||||||
@@ -69,7 +73,11 @@ void TM1638::setDisplayToDecNumber(unsigned long number, byte dots)
|
|||||||
setDisplayDigit(number % 10, 7 - i, (dots & (1 << i)) != 0);
|
setDisplayDigit(number % 10, 7 - i, (dots & (1 << i)) != 0);
|
||||||
number /= 10;
|
number /= 10;
|
||||||
} else {
|
} else {
|
||||||
setDisplayDigit(0, 7 - i, (dots & (1 << i)) != 0);
|
if (leadingZeros) {
|
||||||
|
setDisplayDigit(0, 7 - i, (dots & (1 << i)) != 0);
|
||||||
|
} else {
|
||||||
|
clearDisplayDigit(7 - i, (dots & (1 << i)) != 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -87,6 +95,11 @@ void TM1638::setDisplayDigit(byte digit, byte pos, boolean dot)
|
|||||||
sendData(pos << 1, NUMBER_DATA[digit & 0xF] | (dot ? 0b10000000 : 0));
|
sendData(pos << 1, NUMBER_DATA[digit & 0xF] | (dot ? 0b10000000 : 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TM1638::clearDisplayDigit(byte pos, boolean dot)
|
||||||
|
{
|
||||||
|
sendData(pos << 1, (dot ? 0b10000000 : 0));
|
||||||
|
}
|
||||||
|
|
||||||
void TM1638::setDisplay(const byte values[])
|
void TM1638::setDisplay(const byte values[])
|
||||||
{
|
{
|
||||||
for (int i = 0; i < 8; i++) {
|
for (int i = 0; i < 8; i++) {
|
||||||
|
|||||||
11
TM1638.h
11
TM1638.h
@@ -36,14 +36,16 @@ class TM1638
|
|||||||
/** Set the display (segments and LEDs) active or off and intensity (range from 0-7). */
|
/** Set the display (segments and LEDs) active or off and intensity (range from 0-7). */
|
||||||
void setupDisplay(boolean active, byte intensity);
|
void setupDisplay(boolean active, byte intensity);
|
||||||
|
|
||||||
/** Set the display to a unsigned hexadecimal number */
|
/** Set the display to a unsigned hexadecimal number (with or without leading zeros) */
|
||||||
void setDisplayToHexNumber(unsigned long number, byte dots);
|
void setDisplayToHexNumber(unsigned long number, byte dots, boolean leadingZeros = true);
|
||||||
/** Set the display to a unsigned decimal number */
|
/** Set the display to a unsigned decimal number (with or without leading zeros) */
|
||||||
void setDisplayToDecNumber(unsigned long number, byte dots);
|
void setDisplayToDecNumber(unsigned long number, byte dots, boolean leadingZeros = true);
|
||||||
/** Set the display to a unsigned binary number */
|
/** Set the display to a unsigned binary number */
|
||||||
void setDisplayToBinNumber(byte number, byte dots);
|
void setDisplayToBinNumber(byte number, byte dots);
|
||||||
/** Set a single display at pos (starting at 0) to a digit (left to right) */
|
/** Set a single display at pos (starting at 0) to a digit (left to right) */
|
||||||
void setDisplayDigit(byte digit, byte pos, boolean dot);
|
void setDisplayDigit(byte digit, byte pos, boolean dot);
|
||||||
|
/** Clear a single display at pos (starting at 0, left to right) */
|
||||||
|
void clearDisplayDigit(byte pos, boolean dot);
|
||||||
/** Set the display to the 8 values (left to right) */
|
/** Set the display to the 8 values (left to right) */
|
||||||
void setDisplay(const byte values[]);
|
void setDisplay(const byte values[]);
|
||||||
/** Clear the display */
|
/** Clear the display */
|
||||||
@@ -72,4 +74,3 @@ class TM1638
|
|||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user