From 320ef7d54dd4a09e126362da42a25e8f7af5efd3 Mon Sep 17 00:00:00 2001 From: "rjbatista@gmail.com" Date: Wed, 19 Oct 2011 23:57:43 +0000 Subject: [PATCH] added support for String Object --- CHANGES.txt | 3 ++- TM1638.cpp | 14 ++++++++++++++ TM1638.h | 2 ++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/CHANGES.txt b/CHANGES.txt index 8a23e95..47b8bdf 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,5 +1,6 @@ Version 1.3.0 +- added support for String Object; - added support for removing leading zeros in displaying numbers. Version 1.2.0 @@ -12,4 +13,4 @@ Version 1.1.0 Version 1.0.0 -- initial Release. +- initial release. diff --git a/TM1638.cpp b/TM1638.cpp index 6f16280..d17fdc0 100644 --- a/TM1638.cpp +++ b/TM1638.cpp @@ -20,6 +20,7 @@ along with this program. If not, see . #include "WProgram.h" #include "TM1638.h" +#include "String.h" TM1638::TM1638(byte dataPin, byte clockPin, byte strobePin, boolean activateDisplay, byte intensity) { @@ -121,6 +122,19 @@ void TM1638::setDisplayToString(const char* string, const byte font[]) } } +void TM1638::setDisplayToString(const String string, const byte font[]) +{ + int stringLength = string.length(); + + for (int i = 0; i < 8; i++) { + if (i < stringLength) { + sendData(i << 1, font[string.charAt(i) - 32]); + } else { + sendData(i << 1, 0); + } + } +} + void TM1638::setLED(byte color, byte pos) { sendData((pos << 1) + 1, color); diff --git a/TM1638.h b/TM1638.h index 9c1e596..060b34d 100644 --- a/TM1638.h +++ b/TM1638.h @@ -52,6 +52,8 @@ class TM1638 void clearDisplay(); /** Set the display to the string (defaults to built in font) */ void setDisplayToString(const char* string, const byte font[] = FONT_DEFAULT); + /** Set the display to the String (defaults to built in font) */ + void setDisplayToString(String string, const byte font[] = FONT_DEFAULT); /** Set the LED at pos to color (TM1638_COLOR_RED, TM1638_COLOR_GREEN or both) */ void setLED(byte color, byte pos);