Compare commits
16 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
603f5c0ec9 | ||
|
|
cff5d047bf | ||
|
|
eb4538e162 | ||
|
|
a8bcd661c8 | ||
|
|
7260c88f7d | ||
|
|
7c6678133c | ||
|
|
875235aa15 | ||
|
|
dcf48adb26 | ||
|
|
2c722493c1 | ||
|
|
39fd21d26f | ||
|
|
e582d25e84 | ||
|
|
1f5d4b5d8d | ||
|
|
8cd887a567 | ||
|
|
51c24bfaee | ||
|
|
b6a17f5989 | ||
|
|
19673f8650 |
26
CHANGES.txt
26
CHANGES.txt
@@ -1,6 +1,30 @@
|
|||||||
|
Version 1.5.2
|
||||||
|
|
||||||
|
- ISSUE #9: Backwards compatibility with previous Arduino IDE.
|
||||||
|
|
||||||
|
Version 1.5.1
|
||||||
|
|
||||||
|
- ISSUE #7: New character data in default font for '*';
|
||||||
|
- Minor optimization on inverted TM1638.
|
||||||
|
|
||||||
|
Version 1.5.0
|
||||||
|
|
||||||
|
- support for inverted module;
|
||||||
|
- support for Arduino IDE 1.0;
|
||||||
|
- some restructuring.
|
||||||
|
|
||||||
|
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
|
Version 1.3.1
|
||||||
|
|
||||||
- changed pins to match schematics on project site.
|
- changed pins on the examples to match schematics on project site.
|
||||||
|
|
||||||
Version 1.3.0
|
Version 1.3.0
|
||||||
|
|
||||||
|
|||||||
57
InvertedTM1638.cpp
Normal file
57
InvertedTM1638.cpp
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
/*
|
||||||
|
InvertedTM1638.cpp - Library implementation for inverted TM1638.
|
||||||
|
|
||||||
|
Copyright (C) 2011 Ricardo Batista (rjbatista <at> gmail <dot> com)
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if defined(ARDUINO) && ARDUINO >= 100
|
||||||
|
#include "Arduino.h"
|
||||||
|
#else
|
||||||
|
#include "WProgram.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "InvertedTM1638.h"
|
||||||
|
|
||||||
|
InvertedTM1638::InvertedTM1638(byte dataPin, byte clockPin, byte strobePin, boolean activateDisplay,
|
||||||
|
byte intensity) : TM1638(dataPin, clockPin, strobePin, activateDisplay, intensity)
|
||||||
|
{
|
||||||
|
// nothing to do
|
||||||
|
}
|
||||||
|
|
||||||
|
void InvertedTM1638::setLED(byte color, byte pos)
|
||||||
|
{
|
||||||
|
sendData(((7 - pos) << 1) + 1, color);
|
||||||
|
}
|
||||||
|
|
||||||
|
byte InvertedTM1638::getButtons()
|
||||||
|
{
|
||||||
|
byte buttons = TM1638::getButtons();
|
||||||
|
|
||||||
|
// swap each other
|
||||||
|
buttons = (buttons & 0b01010101) << 1 | (buttons & 0b10101010) >> 1;
|
||||||
|
|
||||||
|
// swap each pair
|
||||||
|
buttons = (buttons & 0b00110011) << 2 | (buttons & 0b11001100) >> 2;
|
||||||
|
|
||||||
|
// swap each quad
|
||||||
|
buttons = (buttons & 0b00001111) << 4 | (buttons & 0b11110000) >> 4;
|
||||||
|
|
||||||
|
return buttons;
|
||||||
|
}
|
||||||
|
|
||||||
|
void InvertedTM1638::sendChar(byte pos, byte data, boolean dot)
|
||||||
|
{
|
||||||
|
TM1638::sendChar(7 - pos, data & 0xC0 | (data & 0x07) << 3 | (data & 0x38) >> 3, dot);
|
||||||
|
}
|
||||||
45
InvertedTM1638.h
Normal file
45
InvertedTM1638.h
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
/*
|
||||||
|
InvertedTM1638.h - Library for an inverted TM1638.
|
||||||
|
|
||||||
|
Copyright (C) 2011 Ricardo Batista <rjbatista at gmail dot com>
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef InvertedTM1638_h
|
||||||
|
#define InvertedTM1638_h
|
||||||
|
|
||||||
|
#if defined(ARDUINO) && ARDUINO >= 100
|
||||||
|
#include "Arduino.h"
|
||||||
|
#else
|
||||||
|
#include "WProgram.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "TM1638.h"
|
||||||
|
|
||||||
|
class InvertedTM1638 : public TM1638
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
/** Instantiate an inverted tm1638 module specifying the display state, the starting intensity (0-7) data, clock and stobe pins. */
|
||||||
|
InvertedTM1638(byte dataPin, byte clockPin, byte strobePin, boolean activateDisplay = true, byte intensity = 7);
|
||||||
|
|
||||||
|
/** Set the LED at pos to color (TM1638_COLOR_RED, TM1638_COLOR_GREEN or both) */
|
||||||
|
virtual void setLED(byte color, byte pos);
|
||||||
|
/** Returns the pressed buttons as a bit set (left to right). */
|
||||||
|
virtual byte getButtons();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual void sendChar(byte pos, byte data, boolean dot);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -11,7 +11,8 @@ Includes:
|
|||||||
- Support for multiple chained tm1638;
|
- Support for multiple chained tm1638;
|
||||||
- Reading simultaneous button presses;
|
- Reading simultaneous button presses;
|
||||||
- Support for dimming the display and LEDs;
|
- Support for dimming the display and LEDs;
|
||||||
- Support for writing text.
|
- Support for writing text;
|
||||||
|
- Support for module in inverted position.
|
||||||
|
|
||||||
See: TM1638 Display/LED module at http://www.dealextreme.com/p/81873?r=68099021
|
See: TM1638 Display/LED module at http://www.dealextreme.com/p/81873?r=68099021
|
||||||
|
|
||||||
|
|||||||
67
TM1638.cpp
67
TM1638.cpp
@@ -1,10 +1,8 @@
|
|||||||
/*
|
/*
|
||||||
TM1638.h - Library for TM1638.
|
TM1638.cpp - Library implementation 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,9 +16,14 @@ You should have received a copy of the GNU General Public License
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#if defined(ARDUINO) && ARDUINO >= 100
|
||||||
|
#include "Arduino.h"
|
||||||
|
#else
|
||||||
#include "WProgram.h"
|
#include "WProgram.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#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)
|
||||||
{
|
{
|
||||||
@@ -51,31 +54,32 @@ void TM1638::setupDisplay(boolean active, byte intensity)
|
|||||||
sendCommand(0x80 | (active ? 8 : 0) | min(7, intensity));
|
sendCommand(0x80 | (active ? 8 : 0) | min(7, intensity));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TM1638::setDisplayToHexNumber(unsigned long number, byte dots, boolean leadingZeros,
|
||||||
void TM1638::setDisplayToHexNumber(unsigned long number, byte dots, boolean leadingZeros)
|
const byte numberFont[])
|
||||||
{
|
{
|
||||||
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, numberFont);
|
||||||
number >>= 4;
|
number >>= 4;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TM1638::setDisplayToDecNumber(unsigned long number, byte dots, boolean leadingZeros)
|
void TM1638::setDisplayToDecNumber(unsigned long number, byte dots, boolean leadingZeros,
|
||||||
|
const byte numberFont[])
|
||||||
{
|
{
|
||||||
if (number > 99999999L) {
|
if (number > 99999999L) {
|
||||||
setDisplay(ERROR);
|
setDisplayToError();
|
||||||
} else {
|
} else {
|
||||||
for (int i = 0; i < 8; i++) {
|
for (int i = 0; i < 8; i++) {
|
||||||
if (number != 0) {
|
if (number != 0) {
|
||||||
setDisplayDigit(number % 10, 7 - i, (dots & (1 << i)) != 0);
|
setDisplayDigit(number % 10, 7 - i, (dots & (1 << i)) != 0, numberFont);
|
||||||
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, numberFont);
|
||||||
} else {
|
} else {
|
||||||
clearDisplayDigit(7 - i, (dots & (1 << i)) != 0);
|
clearDisplayDigit(7 - i, (dots & (1 << i)) != 0);
|
||||||
}
|
}
|
||||||
@@ -84,27 +88,32 @@ void TM1638::setDisplayToDecNumber(unsigned long number, byte dots, boolean lead
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TM1638::setDisplayToBinNumber(byte number, byte dots)
|
void TM1638::setDisplayToBinNumber(byte number, byte dots, const byte numberFont[])
|
||||||
{
|
{
|
||||||
for (int i = 0; i < 8; i++) {
|
for (int i = 0; i < 8; i++) {
|
||||||
setDisplayDigit((number & (1 << i)) == 0 ? 0 : 1, 7 - i, (dots & (1 << i)) != 0);
|
setDisplayDigit((number & (1 << i)) == 0 ? 0 : 1, 7 - i, (dots & (1 << i)) != 0, numberFont);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TM1638::setDisplayDigit(byte digit, byte pos, boolean dot)
|
void TM1638::setDisplayDigit(byte digit, byte pos, boolean dot, const byte numberFont[])
|
||||||
{
|
{
|
||||||
sendData(pos << 1, NUMBER_DATA[digit & 0xF] | (dot ? 0b10000000 : 0));
|
sendChar(pos, numberFont[digit & 0xF], dot);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TM1638::setDisplayToError()
|
||||||
|
{
|
||||||
|
setDisplay(ERROR_DATA);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TM1638::clearDisplayDigit(byte pos, boolean dot)
|
void TM1638::clearDisplayDigit(byte pos, boolean dot)
|
||||||
{
|
{
|
||||||
sendData(pos << 1, (dot ? 0b10000000 : 0));
|
sendChar(pos, 0, dot);
|
||||||
}
|
}
|
||||||
|
|
||||||
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++) {
|
||||||
sendData(i << 1, values[i]);
|
sendChar(i, values[i], 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -115,22 +124,22 @@ 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++) {
|
for (int i = 0; i < 8; i++) {
|
||||||
sendData(i << 1, font[string[i] - 32]);
|
sendChar(i, font[string[i] - 32], dots & (1 << (7 - i)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TM1638::setDisplayToString(const String string, const byte font[])
|
void TM1638::setDisplayToString(const String string, const byte dots, 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]);
|
sendChar(i, font[string.charAt(i) - 32], dots & (1 << (7 - i)));
|
||||||
} else {
|
} else {
|
||||||
sendData(i << 1, 0);
|
sendChar(i, 0, dots & (1 << (7 - i)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -143,17 +152,17 @@ void TM1638::setLED(byte color, byte pos)
|
|||||||
void TM1638::setLEDs(word leds)
|
void TM1638::setLEDs(word leds)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < 8; i++) {
|
for (int i = 0; i < 8; i++) {
|
||||||
byte val = 0;
|
byte color = 0;
|
||||||
|
|
||||||
if (leds & (1 << i)) {
|
if (leds & (1 << i)) {
|
||||||
val |= 1;
|
color |= TM1638_COLOR_RED;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (leds & (1 << (i + 8))) {
|
if (leds & (1 << (i + 8))) {
|
||||||
val |= 2;
|
color |= TM1638_COLOR_GREEN;
|
||||||
}
|
}
|
||||||
|
|
||||||
sendData((i << 1) + 1, val);
|
setLED(color, i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -171,6 +180,11 @@ byte TM1638::getButtons(void)
|
|||||||
return keys;
|
return keys;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TM1638::sendChar(byte pos, byte data, boolean dot)
|
||||||
|
{
|
||||||
|
sendData(pos << 1, data | (dot ? 0b10000000 : 0));
|
||||||
|
}
|
||||||
|
|
||||||
void TM1638::sendCommand(byte cmd)
|
void TM1638::sendCommand(byte cmd)
|
||||||
{
|
{
|
||||||
digitalWrite(strobePin, LOW);
|
digitalWrite(strobePin, LOW);
|
||||||
@@ -223,4 +237,3 @@ byte TM1638::receive()
|
|||||||
|
|
||||||
return temp;
|
return temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
33
TM1638.h
33
TM1638.h
@@ -3,8 +3,6 @@ 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.
|
||||||
@@ -21,7 +19,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
#ifndef TM1638_h
|
#ifndef TM1638_h
|
||||||
#define TM1638_h
|
#define TM1638_h
|
||||||
|
|
||||||
#include <WProgram.h>
|
#if defined(ARDUINO) && ARDUINO >= 100
|
||||||
|
#include "Arduino.h"
|
||||||
|
#else
|
||||||
|
#include "WProgram.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "TM1638Fonts.h"
|
#include "TM1638Fonts.h"
|
||||||
|
|
||||||
#define TM1638_COLOR_RED 1
|
#define TM1638_COLOR_RED 1
|
||||||
@@ -37,13 +40,19 @@ class TM1638
|
|||||||
void setupDisplay(boolean active, byte intensity);
|
void setupDisplay(boolean active, byte intensity);
|
||||||
|
|
||||||
/** Set the display to a unsigned hexadecimal number (with or without leading zeros) */
|
/** Set the display to a unsigned hexadecimal number (with or without leading zeros) */
|
||||||
void setDisplayToHexNumber(unsigned long number, byte dots, boolean leadingZeros = true);
|
void setDisplayToHexNumber(unsigned long number, byte dots, boolean leadingZeros = true,
|
||||||
|
const byte numberFont[] = NUMBER_FONT);
|
||||||
/** 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);
|
||||||
/** 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);
|
||||||
/** 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,
|
||||||
|
const byte numberFont[] = NUMBER_FONT);
|
||||||
|
/** Set the display to an error message */
|
||||||
|
void setDisplayToError();
|
||||||
/** Clear a single display at pos (starting at 0, left to right) */
|
/** Clear a single display at pos (starting at 0, left to right) */
|
||||||
void clearDisplayDigit(byte pos, boolean dot);
|
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) */
|
||||||
@@ -51,19 +60,21 @@ 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 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) */
|
/** Set the display to the String (defaults to built in font) */
|
||||||
void setDisplayToString(String string, const byte font[] = FONT_DEFAULT);
|
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) */
|
/** Set the LED at pos to color (TM1638_COLOR_RED, TM1638_COLOR_GREEN or both) */
|
||||||
void setLED(byte color, byte pos);
|
virtual void setLED(byte color, byte pos);
|
||||||
/** Set the LEDs. MSB byte for the green LEDs, LSB for the red LEDs */
|
/** Set the LEDs. MSB byte for the green LEDs, LSB for the red LEDs */
|
||||||
void setLEDs(word led);
|
void setLEDs(word led);
|
||||||
|
|
||||||
/** Returns the pressed buttons as a bit set (left to right). */
|
/** Returns the pressed buttons as a bit set (left to right). */
|
||||||
byte getButtons();
|
virtual byte getButtons();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
virtual void sendChar(byte pos, byte data, boolean dot);
|
||||||
|
|
||||||
void sendCommand(byte led);
|
void sendCommand(byte led);
|
||||||
void sendData(byte add, byte data);
|
void sendData(byte add, byte data);
|
||||||
void send(byte data);
|
void send(byte data);
|
||||||
|
|||||||
@@ -1,10 +1,8 @@
|
|||||||
/*
|
/*
|
||||||
TM1638.h - Library for TM1638.
|
TM1638Fonts.h - Font definition 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.
|
||||||
@@ -33,7 +31,7 @@ The bits are displayed by mapping bellow
|
|||||||
#define TM1638Fonts_h
|
#define TM1638Fonts_h
|
||||||
|
|
||||||
// definition for standard hexadecimal numbers
|
// definition for standard hexadecimal numbers
|
||||||
const byte NUMBER_DATA[] = {
|
const byte NUMBER_FONT[] = {
|
||||||
0b00111111, // 0
|
0b00111111, // 0
|
||||||
0b00000110, // 1
|
0b00000110, // 1
|
||||||
0b01011011, // 2
|
0b01011011, // 2
|
||||||
@@ -53,7 +51,7 @@ const byte NUMBER_DATA[] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// definition for error
|
// definition for error
|
||||||
const byte ERROR[] = {
|
const byte ERROR_DATA[] = {
|
||||||
0b01111001, // E
|
0b01111001, // E
|
||||||
0b01010000, // r
|
0b01010000, // r
|
||||||
0b01010000, // r
|
0b01010000, // r
|
||||||
@@ -76,7 +74,7 @@ const byte FONT_DEFAULT[] = {
|
|||||||
0b00000010, // (39) '
|
0b00000010, // (39) '
|
||||||
0b00110000, // (40) (
|
0b00110000, // (40) (
|
||||||
0b00000110, // (41) )
|
0b00000110, // (41) )
|
||||||
0b00000000, // (42) *
|
0b01100011, // (42) *
|
||||||
0b00000000, // (43) +
|
0b00000000, // (43) +
|
||||||
0b00000100, // (44) ,
|
0b00000100, // (44) ,
|
||||||
0b01000000, // (45) -
|
0b01000000, // (45) -
|
||||||
|
|||||||
102
examples/tm1638_functions_example/tm1638_functions_example.pde
Normal file
102
examples/tm1638_functions_example/tm1638_functions_example.pde
Normal file
@@ -0,0 +1,102 @@
|
|||||||
|
/*
|
||||||
|
Library examples for TM1638.
|
||||||
|
|
||||||
|
Copyright (C) 2011 Ricardo Batista <rjbatista at gmail dot com>
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <TM1638.h>
|
||||||
|
#include <InvertedTM1638.h>
|
||||||
|
|
||||||
|
#define NO_MODULES 2
|
||||||
|
|
||||||
|
// define a regular module and a inverted module
|
||||||
|
TM1638 module1(3, 2, 4);
|
||||||
|
InvertedTM1638 module2(3, 2, 5);
|
||||||
|
TM1638* modules[NO_MODULES] = {
|
||||||
|
&module1,
|
||||||
|
&module2
|
||||||
|
};
|
||||||
|
byte modes[NO_MODULES];
|
||||||
|
|
||||||
|
unsigned long startTime;
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
startTime = millis();
|
||||||
|
|
||||||
|
for (int i = 0; i < NO_MODULES; i++) {
|
||||||
|
modules[i]->setupDisplay(true, 7);
|
||||||
|
modes[i] = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void update(TM1638* module, byte* mode) {
|
||||||
|
byte buttons = module->getButtons();
|
||||||
|
unsigned long runningSecs = (millis() - startTime) / 1000;
|
||||||
|
|
||||||
|
// button pressed - change mode
|
||||||
|
if (buttons != 0) {
|
||||||
|
*mode = buttons >> 1;
|
||||||
|
module->clearDisplay();
|
||||||
|
module->setLEDs(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (*mode) {
|
||||||
|
case 0:
|
||||||
|
module->setDisplayToDecNumber(runningSecs, 1 << 7);
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
module->setDisplayToDecNumber(runningSecs, 1 << 6, false);
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
module->setDisplayToHexNumber(runningSecs, 1 << 5);
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
module->setDisplayToHexNumber(runningSecs, 1 << 4, false);
|
||||||
|
break;
|
||||||
|
case 8:
|
||||||
|
module->setDisplayToBinNumber(runningSecs, 1 << 3);
|
||||||
|
break;
|
||||||
|
case 16:
|
||||||
|
module->clearDisplayDigit((runningSecs - 1) % 8, 0);
|
||||||
|
module->setDisplayDigit(runningSecs % 8, runningSecs % 8, 0);
|
||||||
|
break;
|
||||||
|
case 32:
|
||||||
|
char s[8];
|
||||||
|
sprintf(s, "Secs %03d", runningSecs % 999);
|
||||||
|
module->setDisplayToString(s);
|
||||||
|
break;
|
||||||
|
case 64:
|
||||||
|
if (runningSecs % 2 == 0) {
|
||||||
|
module->setDisplayToString("TM1638 ");
|
||||||
|
} else {
|
||||||
|
module->setDisplayToString("LIBRARY ");
|
||||||
|
}
|
||||||
|
|
||||||
|
module->setLED(0, (runningSecs - 1) % 8);
|
||||||
|
module->setLED(1 + runningSecs % 3, runningSecs % 8);
|
||||||
|
break;
|
||||||
|
case 65:
|
||||||
|
module->setDisplayToError();
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
for (int i = 0; i < NO_MODULES; i++) {
|
||||||
|
update(modules[i], &modes[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
|
|
||||||
#include <TM1638.h>
|
#include <TM1638.h>
|
||||||
|
|
||||||
// define a module on data pin 3, clock pin 9 and strobe pin 7
|
// define a module on data pin 8, clock pin 9 and strobe pin 7
|
||||||
TM1638 module(8, 9, 7);
|
TM1638 module(8, 9, 7);
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
#######################################
|
#######################################
|
||||||
|
|
||||||
TM1638 KEYWORD1
|
TM1638 KEYWORD1
|
||||||
|
InvertedTM1638 KEYWORD1
|
||||||
|
|
||||||
#######################################
|
#######################################
|
||||||
# Methods and Functions (KEYWORD2)
|
# Methods and Functions (KEYWORD2)
|
||||||
@@ -25,6 +26,7 @@ setLEDs KEYWORD2
|
|||||||
getButtons KEYWORD2
|
getButtons KEYWORD2
|
||||||
sendCommand KEYWORD2
|
sendCommand KEYWORD2
|
||||||
sendData KEYWORD2
|
sendData KEYWORD2
|
||||||
|
sendChar KEYWORD2
|
||||||
send KEYWORD2
|
send KEYWORD2
|
||||||
receive KEYWORD2
|
receive KEYWORD2
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user