1 Commits

Author SHA1 Message Date
rjbatista@gmail.com
1b980da511 Version 1.3.0 2011-10-19 23:58:35 +00:00
6 changed files with 40 additions and 49 deletions

View File

@@ -1,16 +1,3 @@
Version 1.4.0
- ISSUE #6: Support for specifying dots on setDisplayToString
WARNING: setDisplayToString methods have changed prototype and are incompatible with code compiled for 1.3.x (if you specified a custom font)
Version 1.3.2
- ISSUE #5: Correction of string library import
Version 1.3.1
- changed pins on the examples to match schematics on project site.
Version 1.3.0 Version 1.3.0
- added support for String Object; - added support for String Object;

View File

@@ -3,6 +3,8 @@ TM1638.h - Library for TM1638.
Copyright (C) 2011 Ricardo Batista (rjbatista <at> gmail <dot> com) Copyright (C) 2011 Ricardo Batista (rjbatista <at> gmail <dot> com)
Based on a sketch by: Martin Hubacek (http://www.martinhubacek.cz)
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
it under the terms of the version 3 GNU General Public License as it under the terms of the version 3 GNU General Public License as
published by the Free Software Foundation. published by the Free Software Foundation.
@@ -18,7 +20,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "WProgram.h" #include "WProgram.h"
#include "TM1638.h" #include "TM1638.h"
#include "string.h" #include "String.h"
TM1638::TM1638(byte dataPin, byte clockPin, byte strobePin, boolean activateDisplay, byte intensity) TM1638::TM1638(byte dataPin, byte clockPin, byte strobePin, boolean activateDisplay, byte intensity)
{ {
@@ -35,7 +37,7 @@ TM1638::TM1638(byte dataPin, byte clockPin, byte strobePin, boolean activateDisp
sendCommand(0x40); sendCommand(0x40);
sendCommand(0x80 | (activateDisplay ? 8 : 0) | min(7, intensity)); sendCommand(0x80 | (activateDisplay ? 8 : 0) | min(7, intensity));
digitalWrite(strobePin, LOW); digitalWrite(strobePin, LOW);
send(0xC0); send(0xC0);
for (int i = 0; i < 16; i++) { for (int i = 0; i < 16; i++) {
@@ -53,11 +55,11 @@ void TM1638::setupDisplay(boolean active, byte intensity)
void TM1638::setDisplayToHexNumber(unsigned long number, byte dots, boolean leadingZeros) void TM1638::setDisplayToHexNumber(unsigned long number, byte dots, boolean leadingZeros)
{ {
for (int i = 0; i < 8; i++) { for (int i = 0; i < 8; i++) {
if (!leadingZeros && number == 0) { if (!leadingZeros && number == 0) {
clearDisplayDigit(7 - i, (dots & (1 << i)) != 0); clearDisplayDigit(7 - i, (dots & (1 << i)) != 0);
} else { } else {
setDisplayDigit(number & 0xF, 7 - i, (dots & (1 << i)) != 0); setDisplayDigit(number & 0xF, 7 - i, (dots & (1 << i)) != 0);
number >>= 4; number >>= 4;
} }
} }
} }
@@ -72,11 +74,11 @@ void TM1638::setDisplayToDecNumber(unsigned long number, byte dots, boolean lead
setDisplayDigit(number % 10, 7 - i, (dots & (1 << i)) != 0); setDisplayDigit(number % 10, 7 - i, (dots & (1 << i)) != 0);
number /= 10; number /= 10;
} else { } else {
if (leadingZeros) { if (leadingZeros) {
setDisplayDigit(0, 7 - i, (dots & (1 << i)) != 0); setDisplayDigit(0, 7 - i, (dots & (1 << i)) != 0);
} else { } else {
clearDisplayDigit(7 - i, (dots & (1 << i)) != 0); clearDisplayDigit(7 - i, (dots & (1 << i)) != 0);
} }
} }
} }
} }
@@ -113,29 +115,29 @@ void TM1638::clearDisplay()
} }
} }
void TM1638::setDisplayToString(const char* string, const byte dots, const byte font[]) void TM1638::setDisplayToString(const char* string, const byte font[])
{ {
for (int i = 0; i < 8; i++) { for (int i = 0; i < 8; i++) {
sendData(i << 1, font[string[i] - 32] | ((dots & (1 << (7 - i))) != 0 ? 0b10000000 : 0)); sendData(i << 1, font[string[i] - 32]);
} }
} }
void TM1638::setDisplayToString(const String string, const byte dots, const byte font[]) void TM1638::setDisplayToString(const String string, const byte font[])
{ {
int stringLength = string.length(); int stringLength = string.length();
for (int i = 0; i < 8; i++) { for (int i = 0; i < 8; i++) {
if (i < stringLength) { if (i < stringLength) {
sendData(i << 1, font[string.charAt(i) - 32] | ((dots & (1 << (7 - i))) != 0 ? 0b10000000 : 0)); sendData(i << 1, font[string.charAt(i) - 32]);
} else { } else {
sendData(i << 1, 0); sendData(i << 1, 0);
} }
} }
} }
void TM1638::setLED(byte color, byte pos) void TM1638::setLED(byte color, byte pos)
{ {
sendData((pos << 1) + 1, color); sendData((pos << 1) + 1, color);
} }
void TM1638::setLEDs(word leds) void TM1638::setLEDs(word leds)
@@ -146,7 +148,7 @@ void TM1638::setLEDs(word leds)
if (leds & (1 << i)) { if (leds & (1 << i)) {
val |= 1; val |= 1;
} }
if (leds & (1 << (i + 8))) { if (leds & (1 << (i + 8))) {
val |= 2; val |= 2;
} }
@@ -159,7 +161,7 @@ byte TM1638::getButtons(void)
{ {
byte keys = 0; byte keys = 0;
digitalWrite(strobePin, LOW); digitalWrite(strobePin, LOW);
send(0x42); send(0x42);
for (int i = 0; i < 4; i++) { for (int i = 0; i < 4; i++) {
keys |= receive() << i; keys |= receive() << i;
@@ -201,23 +203,23 @@ byte TM1638::receive()
// Pull-up on // Pull-up on
pinMode(dataPin, INPUT); pinMode(dataPin, INPUT);
digitalWrite(dataPin, HIGH); digitalWrite(dataPin, HIGH);
for (int i = 0; i < 8; i++) { for (int i = 0; i < 8; i++) {
temp >>= 1; temp >>= 1;
digitalWrite(clockPin, LOW); digitalWrite(clockPin, LOW);
if (digitalRead(dataPin)) { if (digitalRead(dataPin)) {
temp |= 0x80; temp |= 0x80;
} }
digitalWrite(clockPin, HIGH); digitalWrite(clockPin, HIGH);
} }
// Pull-up off // Pull-up off
pinMode(dataPin, OUTPUT); pinMode(dataPin, OUTPUT);
digitalWrite(dataPin, LOW); digitalWrite(dataPin, LOW);
return temp; return temp;
} }

View File

@@ -3,6 +3,8 @@ TM1638.h - Library for TM1638.
Copyright (C) 2011 Ricardo Batista <rjbatista at gmail dot com> Copyright (C) 2011 Ricardo Batista <rjbatista at gmail dot com>
Based on a sketch by: Martin Hubacek (http://www.martinhubacek.cz)
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
it under the terms of the version 3 GNU General Public License as it under the terms of the version 3 GNU General Public License as
published by the Free Software Foundation. published by the Free Software Foundation.
@@ -49,9 +51,9 @@ class TM1638
/** Clear the display */ /** Clear the display */
void clearDisplay(); void clearDisplay();
/** Set the display to the string (defaults to built in font) */ /** Set the display to the string (defaults to built in font) */
void setDisplayToString(const char* string, const byte dots = 0, const byte font[] = FONT_DEFAULT); void setDisplayToString(const char* string, const byte font[] = FONT_DEFAULT);
/** Set the display to the String (defaults to built in font) */ /** Set the display to the String (defaults to built in font) */
void setDisplayToString(String string, const byte dots = 0, const byte font[] = FONT_DEFAULT); void setDisplayToString(String string, const byte font[] = FONT_DEFAULT);
/** Set the LED at pos to color (TM1638_COLOR_RED, TM1638_COLOR_GREEN or both) */ /** Set the LED at pos to color (TM1638_COLOR_RED, TM1638_COLOR_GREEN or both) */
void setLED(byte color, byte pos); void setLED(byte color, byte pos);

View File

@@ -18,8 +18,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <TM1638.h> #include <TM1638.h>
// define a module on data pin 8, clock pin 9 and strobe pin 7 // define a module on data pin 3, clock pin 2 and strobe pin 4
TM1638 module(8, 9, 7); TM1638 module(3, 2, 4);
void setup() { void setup() {
// display a hexadecimal number and set the left 4 dots // display a hexadecimal number and set the left 4 dots

View File

@@ -22,10 +22,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
// define a modules // define a modules
TM1638 modules[] = { TM1638 modules[] = {
TM1638(8, 9, 7), TM1638(3, 2, 4),
TM1638(8, 9, 6), TM1638(3, 2, 5),
TM1638(8, 9, 5), TM1638(3, 2, 6),
TM1638(8, 9, 4) TM1638(3, 2, 7)
}; };
void setup() { void setup() {

View File

@@ -24,9 +24,9 @@ const byte hello[] = {
}; };
// define the first module // define the first module
TM1638 module1(8, 9, 7); TM1638 module1(3, 2, 4);
// to chain modules, use the same clk and data - just specify a different strobe pin // to chain modules, use the same clk and data - just specify a different strobe pin
TM1638 module2(8, 9, 6); TM1638 module2(3, 2, 5);
unsigned long value = 0L; unsigned long value = 0L;
boolean state = true; boolean state = true;