Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9350f93996 | ||
|
|
1c5a92c9fe | ||
|
|
1f5d4b5d8d | ||
|
|
8cd887a567 | ||
|
|
51c24bfaee | ||
|
|
b6a17f5989 | ||
|
|
19673f8650 | ||
|
|
2def3b9779 | ||
|
|
81aa413f28 | ||
|
|
320ef7d54d | ||
|
|
e3075c02e2 |
29
CHANGES.txt
Normal file
29
CHANGES.txt
Normal file
@@ -0,0 +1,29 @@
|
||||
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
|
||||
|
||||
- added support for String Object;
|
||||
- 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.
|
||||
39
TM1638.cpp
39
TM1638.cpp
@@ -3,8 +3,6 @@ TM1638.h - Library for TM1638.
|
||||
|
||||
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
|
||||
it under the terms of the version 3 GNU General Public License as
|
||||
published by the Free Software Foundation.
|
||||
@@ -20,6 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#include "WProgram.h"
|
||||
#include "TM1638.h"
|
||||
#include "string.h"
|
||||
|
||||
TM1638::TM1638(byte dataPin, byte clockPin, byte strobePin, boolean activateDisplay, byte intensity)
|
||||
{
|
||||
@@ -51,15 +50,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++) {
|
||||
if (!leadingZeros && number == 0) {
|
||||
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) {
|
||||
setDisplay(ERROR);
|
||||
@@ -69,7 +72,11 @@ void TM1638::setDisplayToDecNumber(unsigned long number, byte dots)
|
||||
setDisplayDigit(number % 10, 7 - i, (dots & (1 << i)) != 0);
|
||||
number /= 10;
|
||||
} 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 +94,11 @@ void TM1638::setDisplayDigit(byte digit, byte pos, boolean dot)
|
||||
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[])
|
||||
{
|
||||
for (int i = 0; i < 8; i++) {
|
||||
@@ -101,10 +113,23 @@ void TM1638::clearDisplay()
|
||||
}
|
||||
}
|
||||
|
||||
void TM1638::setDisplayToString(const char* string, const byte font[])
|
||||
void TM1638::setDisplayToString(const char* string, const byte dots, const byte font[])
|
||||
{
|
||||
for (int i = 0; i < 8; i++) {
|
||||
sendData(i << 1, font[string[i] - 32]);
|
||||
sendData(i << 1, font[string[i] - 32] | ((dots & (1 << (7 - i))) != 0 ? 0b10000000 : 0));
|
||||
}
|
||||
}
|
||||
|
||||
void TM1638::setDisplayToString(const String string, const byte dots, 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] | ((dots & (1 << (7 - i))) != 0 ? 0b10000000 : 0));
|
||||
} else {
|
||||
sendData(i << 1, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
17
TM1638.h
17
TM1638.h
@@ -3,8 +3,6 @@ TM1638.h - Library for TM1638.
|
||||
|
||||
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
|
||||
it under the terms of the version 3 GNU General Public License as
|
||||
published by the Free Software Foundation.
|
||||
@@ -36,20 +34,24 @@ class TM1638
|
||||
/** Set the display (segments and LEDs) active or off and intensity (range from 0-7). */
|
||||
void setupDisplay(boolean active, byte intensity);
|
||||
|
||||
/** Set the display to a unsigned hexadecimal number */
|
||||
void setDisplayToHexNumber(unsigned long number, byte dots);
|
||||
/** Set the display to a unsigned decimal number */
|
||||
void setDisplayToDecNumber(unsigned long number, byte dots);
|
||||
/** Set the display to a unsigned hexadecimal number (with or without leading zeros) */
|
||||
void setDisplayToHexNumber(unsigned long number, byte dots, boolean leadingZeros = true);
|
||||
/** Set the display to a unsigned decimal number (with or without leading zeros) */
|
||||
void setDisplayToDecNumber(unsigned long number, byte dots, boolean leadingZeros = true);
|
||||
/** Set the display to a unsigned binary number */
|
||||
void setDisplayToBinNumber(byte number, byte dots);
|
||||
/** Set a single display at pos (starting at 0) to a digit (left to right) */
|
||||
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) */
|
||||
void setDisplay(const byte values[]);
|
||||
/** Clear the display */
|
||||
void clearDisplay();
|
||||
/** Set the display to the string (defaults to built in font) */
|
||||
void setDisplayToString(const char* string, const byte font[] = FONT_DEFAULT);
|
||||
void setDisplayToString(const char* string, const byte dots = 0, const byte font[] = FONT_DEFAULT);
|
||||
/** Set the display to the String (defaults to built in font) */
|
||||
void setDisplayToString(String string, const byte dots = 0, 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);
|
||||
@@ -72,4 +74,3 @@ class TM1638
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -18,8 +18,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#include <TM1638.h>
|
||||
|
||||
// define a module on data pin 3, clock pin 2 and strobe pin 4
|
||||
TM1638 module(3, 2, 4);
|
||||
// define a module on data pin 8, clock pin 9 and strobe pin 7
|
||||
TM1638 module(8, 9, 7);
|
||||
|
||||
void setup() {
|
||||
// display a hexadecimal number and set the left 4 dots
|
||||
|
||||
@@ -22,10 +22,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
// define a modules
|
||||
TM1638 modules[] = {
|
||||
TM1638(3, 2, 4),
|
||||
TM1638(3, 2, 5),
|
||||
TM1638(3, 2, 6),
|
||||
TM1638(3, 2, 7)
|
||||
TM1638(8, 9, 7),
|
||||
TM1638(8, 9, 6),
|
||||
TM1638(8, 9, 5),
|
||||
TM1638(8, 9, 4)
|
||||
};
|
||||
|
||||
void setup() {
|
||||
|
||||
@@ -24,9 +24,9 @@ const byte hello[] = {
|
||||
};
|
||||
|
||||
// define the first module
|
||||
TM1638 module1(3, 2, 4);
|
||||
TM1638 module1(8, 9, 7);
|
||||
// to chain modules, use the same clk and data - just specify a different strobe pin
|
||||
TM1638 module2(3, 2, 5);
|
||||
TM1638 module2(8, 9, 6);
|
||||
|
||||
unsigned long value = 0L;
|
||||
boolean state = true;
|
||||
|
||||
Reference in New Issue
Block a user