18 Commits

Author SHA1 Message Date
rjbatista@gmail.com
576de31143 2012-11-06 22:02:06 +00:00
rjbatista@gmail.com
80f687aff6 Version 2.1.3 2012-11-06 22:01:32 +00:00
rjbatista@gmail.com
00cd075f69 2012-11-06 22:00:56 +00:00
rjbatista@gmail.com
6b4cfae6e5 2012-11-06 21:57:35 +00:00
rjbatista@gmail.com
1508d99abb Version 2.1.2 2012-06-11 21:38:49 +00:00
rjbatista@gmail.com
b779a65eb9 ISSUE #22: corrected setDisplayDigit repeatedly with the dot set to true 2012-06-11 21:16:15 +00:00
rjbatista@gmail.com
7a94b31533 ISSUE #24: Correction on setDisplayToDecNumber bug (thanks to hbx3485); 2012-06-11 21:07:45 +00:00
rjbatista@gmail.com
e4a7aad4d7 ISSUE #24: Correction on setDisplayToDecNumber bug (thanks hbx3485) 2012-06-11 21:05:16 +00:00
rjbatista@gmail.com
5756b7ae7d 2012-03-13 00:05:08 +00:00
rjbatista@gmail.com
da0b7ec9e2 Version 2.1.1 2012-03-12 23:59:00 +00:00
rjbatista@gmail.com
8ba4623718 ISSUE #21: Problems on clearDisplay and setupDisplay 2012-03-12 23:58:28 +00:00
rjbatista@gmail.com
cb437405ea Version 2.1.0 2012-02-20 22:18:16 +00:00
rjbatista@gmail.com
f52570e011 ISSUE #20: Support for negative decimal numbers 2012-02-20 22:17:47 +00:00
rjbatista@gmail.com
8b1fda292d ISSUE #19: Corrected setDisplayToString dot bug 2012-02-20 21:29:32 +00:00
rjbatista@gmail.com
5e2afcdaeb Version 2.0.1 2012-01-18 00:02:19 +00:00
rjbatista@gmail.com
bdee0e3872 ISSUE #15: Backwards compatibility with previous Arduino IDE (pure virtual functions were not supported) 2012-01-17 22:52:47 +00:00
rjbatista@gmail.com
fb4924cc0a ISSUE #18: Corrected problem with setLEDs() caused by changes in the previous version 2012-01-17 22:19:00 +00:00
rjbatista@gmail.com
ca9bc6f3bb 2012-01-11 02:14:18 +00:00
8 changed files with 96 additions and 12 deletions

View File

@@ -1,3 +1,26 @@
Version 2.1.3
- ISSUE #26: Added a define TM1638_COLOR_NONE for clarity when clearing a single LED.
Version 2.1.2
- ISSUE #22: Corrected setDisplayDigit repeatedly with the dot set to true;
- ISSUE #24: Correction on setDisplayToDecNumber bug (thanks to hbx3485).
Version 2.1.1
- ISSUE #21: Problems on clearDisplay and setupDisplay.
Version 2.1.0
- ISSUE #20: Support for negative decimal numbers;
- ISSUE #19: Corrected setDisplayToString dot bug.
Version 2.0.1
- ISSUE #15: Backwards compatibility with previous Arduino IDE (pure virtual functions were not supported);
- ISSUE #18: Corrected problem with setLEDs() caused by changes in the previous version.
Version 2.0.0 Version 2.0.0
- Support for the TM1640; - Support for the TM1640;

View File

@@ -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[]) const byte numberFont[])
{ {
if (number > 99999999L) { if (number > 99999999L) {
setDisplayToError(); setDisplayToError();
} else { } else {
for (int i = 0; i < displays; i++) { for (int i = 0; i < displays - startingPos; i++) {
if (number != 0) { if (number != 0) {
setDisplayDigit(number % 10, displays - i - 1, (dots & (1 << i)) != 0, numberFont); setDisplayDigit(number % 10, displays - i - 1, (dots & (1 << i)) != 0, numberFont);
number /= 10; number /= 10;
} else { } else {
if (leadingZeros) { if (leadingZeros) {
setDisplayDigit(0, displays - i - 1, (dots & (1 << i)) != 0, numberFont); setDisplayDigit(0, displays - i - 1, (dots & (1 << i)) != 0, numberFont);
} else { } else {
clearDisplayDigit(displays - i - 1, (dots & (1 << i)) != 0); 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, 0, leadingZeros, 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[]) void TM1638::setDisplayToBinNumber(byte number, byte dots, const byte numberFont[])
{ {
for (int i = 0; i < displays; i++) { for (int i = 0; i < displays; i++) {
@@ -82,11 +103,11 @@ void TM1638::setLEDs(word leds)
for (int i = 0; i < displays; i++) { for (int i = 0; i < displays; i++) {
byte color = 0; byte color = 0;
if (leds & (1 << i) != 0) { if ((leds & (1 << i)) != 0) {
color |= TM1638_COLOR_RED; color |= TM1638_COLOR_RED;
} }
if (leds & (1 << (i + 8)) != 0) { if ((leds & (1 << (i + 8))) != 0) {
color |= TM1638_COLOR_GREEN; color |= TM1638_COLOR_GREEN;
} }

View File

@@ -28,6 +28,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "TM16XX.h" #include "TM16XX.h"
#include "TM16XXFonts.h" #include "TM16XXFonts.h"
#define TM1638_COLOR_NONE 0
#define TM1638_COLOR_RED 1 #define TM1638_COLOR_RED 1
#define TM1638_COLOR_GREEN 2 #define TM1638_COLOR_GREEN 2
@@ -43,6 +44,9 @@ class TM1638 : public TM16XX
/** Set the display to a unsigned decimal number (with or without leading zeros) */ /** Set the display to a unsigned decimal number (with or without leading zeros) */
void setDisplayToDecNumber(unsigned long number, byte dots, boolean leadingZeros = true, void setDisplayToDecNumber(unsigned long number, byte dots, boolean leadingZeros = true,
const byte numberFont[] = NUMBER_FONT); 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 */ /** Set the display to a unsigned binary number */
void setDisplayToBinNumber(byte number, byte dots, void setDisplayToBinNumber(byte number, byte dots,
const byte numberFont[] = NUMBER_FONT); const byte numberFont[] = NUMBER_FONT);
@@ -57,6 +61,8 @@ class TM1638 : public TM16XX
protected: protected:
virtual void sendChar(byte pos, byte data, boolean dot); virtual void sendChar(byte pos, byte data, boolean dot);
void setDisplayToDecNumberAt(unsigned long number, byte dots, byte startingPos,
boolean leadingZeros, const byte numberFont[]);
}; };
#endif #endif

View File

@@ -35,4 +35,20 @@ TM1640::TM1640(byte dataPin, byte clockPin, boolean activateDisplay, byte intens
void TM1640::sendChar(byte pos, byte data, boolean dot) void TM1640::sendChar(byte pos, byte data, boolean dot)
{ {
sendData(pos, data | (dot ? 0b10000000 : 0)); sendData(pos, data | (dot ? 0b10000000 : 0));
// necessary for the TM1640
digitalWrite(strobePin, LOW);
digitalWrite(clockPin, LOW);
digitalWrite(clockPin, HIGH);
digitalWrite(strobePin, HIGH);
}
void TM1640::clearDisplay()
{
digitalWrite(strobePin, LOW);
send(0xC0);
for (int i = 0; i < 16; i++) {
send(0x00);
}
digitalWrite(strobePin, HIGH);
} }

View File

@@ -33,10 +33,8 @@ class TM1640 : public TM16XX
public: public:
/** Instantiate a tm1640 module specifying the display state, the starting intensity (0-7) data and clock pins. */ /** Instantiate a tm1640 module specifying the display state, the starting intensity (0-7) data and clock pins. */
TM1640(byte dataPin, byte clockPin, boolean activateDisplay = true, byte intensity = 7); TM1640(byte dataPin, byte clockPin, boolean activateDisplay = true, byte intensity = 7);
/** Clear the display */
/** Set the display to a unsigned decimal number (with or without leading zeros) */ virtual void clearDisplay();
void setDisplayToDecNumber(unsigned long number, word dots, boolean leadingZeros = true,
const byte numberFont[] = NUMBER_FONT);
protected: protected:
virtual void sendChar(byte pos, byte data, boolean dot); virtual void sendChar(byte pos, byte data, boolean dot);

View File

@@ -54,6 +54,12 @@ TM16XX::TM16XX(byte dataPin, byte clockPin, byte strobePin, byte displays, boole
void TM16XX::setupDisplay(boolean active, byte intensity) void TM16XX::setupDisplay(boolean active, byte intensity)
{ {
sendCommand(0x80 | (active ? 8 : 0) | min(7, intensity)); sendCommand(0x80 | (active ? 8 : 0) | min(7, intensity));
// necessary for the TM1640
digitalWrite(strobePin, LOW);
digitalWrite(clockPin, LOW);
digitalWrite(clockPin, HIGH);
digitalWrite(strobePin, HIGH);
} }
void TM16XX::setDisplayDigit(byte digit, byte pos, boolean dot, const byte numberFont[]) void TM16XX::setDisplayDigit(byte digit, byte pos, boolean dot, const byte numberFont[])
@@ -93,7 +99,7 @@ void TM16XX::setDisplayToString(const char* string, const word dots, const byte
{ {
for (int i = 0; i < displays - pos; i++) { for (int i = 0; i < displays - pos; i++) {
if (string[i] != '\0') { if (string[i] != '\0') {
sendChar(i + pos, font[string[i] - 32], dots & (1 << (displays - i - 1)) != 0); sendChar(i + pos, font[string[i] - 32], (dots & (1 << (displays - i - 1))) != 0);
} else { } else {
break; break;
} }
@@ -106,7 +112,7 @@ void TM16XX::setDisplayToString(const String string, const word dots, const byte
for (int i = 0; i < displays - pos; i++) { for (int i = 0; i < displays - pos; i++) {
if (i < stringLength) { if (i < stringLength) {
sendChar(i + pos, font[string.charAt(i) - 32], dots & (1 << (displays - i - 1)) != 0); sendChar(i + pos, font[string.charAt(i) - 32], (dots & (1 << (displays - i - 1))) != 0);
} else { } else {
break; break;
} }
@@ -165,3 +171,9 @@ byte TM16XX::receive()
return temp; return temp;
} }
#if !defined(ARDUINO) || ARDUINO < 100
// empty implementation instead of pure virtual for older Arduino IDE
void TM16XX::sendChar(byte pos, byte data, boolean dot) {}
#endif

View File

@@ -59,7 +59,13 @@ class TM16XX
const byte font[] = FONT_DEFAULT); const byte font[] = FONT_DEFAULT);
protected: protected:
virtual void sendChar(byte pos, byte data, boolean dot) = 0; #if defined(ARDUINO) && ARDUINO >= 100
// pure virtual is NOT supported in older Arduino IDE
virtual void sendChar(byte pos, byte data, boolean dot) = 0;
#else
virtual void sendChar(byte pos, byte data, boolean dot);
#endif
virtual void sendCommand(byte led); virtual void sendCommand(byte led);
virtual void sendData(byte add, byte data); virtual void sendData(byte add, byte data);

View File

@@ -50,6 +50,8 @@ const byte NUMBER_FONT[] = {
0b01110001 // F 0b01110001 // F
}; };
const byte MINUS = 0b01000000;
// definition for error // definition for error
const byte ERROR_DATA[] = { const byte ERROR_DATA[] = {
0b01111001, // E 0b01111001, // E