Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
43e7db902b |
77
CHANGES.txt
77
CHANGES.txt
@@ -1,77 +0,0 @@
|
|||||||
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
|
|
||||||
|
|
||||||
- Support for the TM1640;
|
|
||||||
- Restructuring for supporting other modules.
|
|
||||||
|
|
||||||
Version 1.6.0
|
|
||||||
|
|
||||||
- ISSUE #10: Support for starting position on setDisplayToString() methods.
|
|
||||||
WARNING: setDisplayToString methods have changed prototype and are incompatible with code compiled for 1.5.x (if you specified a custom font)
|
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
- 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.
|
|
||||||
@@ -1,57 +0,0 @@
|
|||||||
/*
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
@@ -1,45 +0,0 @@
|
|||||||
/*
|
|
||||||
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
|
|
||||||
18
README.txt
18
README.txt
@@ -4,27 +4,19 @@ Ricardo Batista
|
|||||||
Email: rjbatista(at)gmail.com
|
Email: rjbatista(at)gmail.com
|
||||||
URL: http://code.google.com/p/tm1638-library/
|
URL: http://code.google.com/p/tm1638-library/
|
||||||
|
|
||||||
A library for interacting an arduino with a TM1638/TM1640.
|
A library for interacting an arduino with a tm1638.
|
||||||
|
|
||||||
Includes:
|
Includes:
|
||||||
- Support for the TM1638 and TM1640;
|
|
||||||
- Helper methods for displaying numbers in decimal, hexadecimal and binary;
|
- Helper methods for displaying numbers in decimal, hexadecimal and binary;
|
||||||
- Support for multiple chained tm1638;
|
- Support for multiple chained tm1638; Reading
|
||||||
- Reading simultaneous button presses;
|
- simultaneous button presses.
|
||||||
- Support for dimming the display and LEDs;
|
|
||||||
- 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
|
||||||
See: TM1640 Display module at http://www.dealextreme.com/p/104311?r=68099021
|
|
||||||
|
|
||||||
USAGE NOTES
|
|
||||||
-----------
|
|
||||||
|
|
||||||
Just put the files on a TM1638 directory under "arduino/libraries" on your arduino IDE instalation
|
|
||||||
|
|
||||||
|
|
||||||
PROJECT HOME
|
PROJECT HOME
|
||||||
------------
|
------------
|
||||||
|
|
||||||
http://code.google.com/p/tm1638-library/
|
http://code.google.com/p/tm1638-library/
|
||||||
210
TM1638.cpp
210
TM1638.cpp
@@ -1,8 +1,10 @@
|
|||||||
/*
|
/*
|
||||||
TM1638.cpp - Library implementation for TM1638.
|
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.
|
||||||
@@ -16,102 +18,141 @@ 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 "WProgram.h"
|
||||||
#include "Arduino.h"
|
|
||||||
#else
|
|
||||||
#include "WProgram.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "TM1638.h"
|
#include "TM1638.h"
|
||||||
#include "string.h"
|
|
||||||
|
/*
|
||||||
|
The bits are displayed by mapping bellow
|
||||||
|
-- 0 --
|
||||||
|
| |
|
||||||
|
5 1
|
||||||
|
-- 6 --
|
||||||
|
4 2
|
||||||
|
| |
|
||||||
|
-- 3 -- .7
|
||||||
|
*/
|
||||||
|
const byte NUMBER_DATA[] = {
|
||||||
|
0b00111111, // 0
|
||||||
|
0b00000110, // 1
|
||||||
|
0b01011011, // 2
|
||||||
|
0b01001111, // 3
|
||||||
|
0b01100110, // 4
|
||||||
|
0b01101101, // 5
|
||||||
|
0b01111101, // 6
|
||||||
|
0b00000111, // 7
|
||||||
|
0b01111111, // 8
|
||||||
|
0b01101111, // 9
|
||||||
|
0b01110111, // A
|
||||||
|
0b01111100, // B
|
||||||
|
0b00111001, // C
|
||||||
|
0b01011110, // D
|
||||||
|
0b01111001, // E
|
||||||
|
0b01110001 // F
|
||||||
|
};
|
||||||
|
|
||||||
|
const byte ERROR[] = {
|
||||||
|
0b01111001, // E
|
||||||
|
0b01010000, // r
|
||||||
|
0b01010000, // r
|
||||||
|
0b01011100, // o
|
||||||
|
0b01010000, // r
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0
|
||||||
|
};
|
||||||
|
|
||||||
TM1638::TM1638(byte dataPin, byte clockPin, byte strobePin, boolean activateDisplay, byte intensity)
|
TM1638::TM1638(byte dataPin, byte clockPin, byte strobePin, boolean activateDisplay, byte intensity)
|
||||||
: TM16XX(dataPin, clockPin, strobePin, 8, activateDisplay, intensity)
|
|
||||||
{
|
{
|
||||||
// nothing else to do - calling super is enough
|
this->dataPin = dataPin;
|
||||||
|
this->clockPin = clockPin;
|
||||||
|
this->strobePin = strobePin;
|
||||||
|
|
||||||
|
pinMode(dataPin, OUTPUT);
|
||||||
|
pinMode(clockPin, OUTPUT);
|
||||||
|
pinMode(strobePin, OUTPUT);
|
||||||
|
|
||||||
|
digitalWrite(strobePin, HIGH);
|
||||||
|
digitalWrite(clockPin, HIGH);
|
||||||
|
|
||||||
|
sendCommand(0x40);
|
||||||
|
sendCommand(0x80 | (activateDisplay ? 8 : 0) | min(7, intensity));
|
||||||
|
|
||||||
|
digitalWrite(strobePin, LOW);
|
||||||
|
send(0xC0);
|
||||||
|
for (int i = 0; i < 16; i++) {
|
||||||
|
send(0x00);
|
||||||
|
}
|
||||||
|
digitalWrite(strobePin, HIGH);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TM1638::setDisplayToHexNumber(unsigned long number, byte dots, boolean leadingZeros,
|
void TM1638::setupDisplay(boolean active, byte intensity)
|
||||||
const byte numberFont[])
|
|
||||||
{
|
{
|
||||||
for (int i = 0; i < displays; i++) {
|
sendCommand(0x80 | (active ? 8 : 0) | min(7, intensity));
|
||||||
if (!leadingZeros && number == 0) {
|
}
|
||||||
clearDisplayDigit(displays - i - 1, (dots & (1 << i)) != 0);
|
|
||||||
} else {
|
|
||||||
setDisplayDigit(number & 0xF, displays - i - 1, (dots & (1 << i)) != 0, numberFont);
|
void TM1638::setDisplayToHexNumber(unsigned long number, byte dots)
|
||||||
number >>= 4;
|
{
|
||||||
}
|
for (int i = 0; i < 8; i++) {
|
||||||
|
setDisplayDigit(number & 0xF, 7 - i, (dots & (1 << i)) != 0);
|
||||||
|
number >>= 4;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TM1638::setDisplayToDecNumberAt(unsigned long number, byte dots, byte startingPos, boolean leadingZeros,
|
void TM1638::setDisplayToDecNumber(unsigned long number, byte dots)
|
||||||
const byte numberFont[])
|
|
||||||
{
|
{
|
||||||
if (number > 99999999L) {
|
if (number > 99999999L) {
|
||||||
setDisplayToError();
|
setDisplay(ERROR);
|
||||||
} else {
|
} else {
|
||||||
for (int i = 0; i < displays - startingPos; i++) {
|
for (int i = 0; i < 8; i++) {
|
||||||
if (number != 0) {
|
if (number != 0) {
|
||||||
setDisplayDigit(number % 10, displays - i - 1, (dots & (1 << i)) != 0, numberFont);
|
setDisplayDigit(number % 10, 7 - i, (dots & (1 << i)) != 0);
|
||||||
number /= 10;
|
number /= 10;
|
||||||
} else {
|
} else {
|
||||||
if (leadingZeros) {
|
setDisplayDigit(0, 7 - i, (dots & (1 << i)) != 0);
|
||||||
setDisplayDigit(0, displays - i - 1, (dots & (1 << i)) != 0, numberFont);
|
|
||||||
} else {
|
|
||||||
clearDisplayDigit(displays - i - 1, (dots & (1 << i)) != 0);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TM1638::setDisplayToDecNumber(unsigned long number, byte dots, boolean leadingZeros,
|
void TM1638::setDisplayToBinNumber(byte number, byte dots)
|
||||||
const byte numberFont[])
|
|
||||||
{
|
{
|
||||||
setDisplayToDecNumberAt(number, dots, 0, leadingZeros, numberFont);
|
for (int i = 0; i < 8; i++) {
|
||||||
|
setDisplayDigit((number & (1 << i)) == 0 ? 0 : 1, 7 - i, (dots & (1 << i)) != 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TM1638::setDisplayToSignedDecNumber(signed long number, byte dots, boolean leadingZeros,
|
void TM1638::setDisplayDigit(byte digit, byte pos, boolean dot)
|
||||||
const byte numberFont[])
|
|
||||||
{
|
{
|
||||||
if (number >= 0) {
|
sendData(pos << 1, NUMBER_DATA[digit & 0xF] | (dot ? 0b10000000 : 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::setDisplay(const byte values[])
|
||||||
{
|
{
|
||||||
for (int i = 0; i < displays; i++) {
|
for (int i = 0; i < 8; i++) {
|
||||||
setDisplayDigit((number & (1 << i)) == 0 ? 0 : 1, displays - i - 1, (dots & (1 << i)) != 0, numberFont);
|
sendData(i << 1, values[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < displays; i++) {
|
for (int i = 0; i < 8; i++) {
|
||||||
byte color = 0;
|
byte val = 0;
|
||||||
|
|
||||||
if ((leds & (1 << i)) != 0) {
|
if (leds & (1 << i)) {
|
||||||
color |= TM1638_COLOR_RED;
|
val |= 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (leds & (1 << (i + 8))) {
|
||||||
|
val |= 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((leds & (1 << (i + 8))) != 0) {
|
sendData((i << 1) + 1, val);
|
||||||
color |= TM1638_COLOR_GREEN;
|
|
||||||
}
|
|
||||||
|
|
||||||
setLED(color, i);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -119,7 +160,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;
|
||||||
@@ -129,7 +170,56 @@ byte TM1638::getButtons(void)
|
|||||||
return keys;
|
return keys;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TM1638::sendChar(byte pos, byte data, boolean dot)
|
void TM1638::sendCommand(byte cmd)
|
||||||
{
|
{
|
||||||
sendData(pos << 1, data | (dot ? 0b10000000 : 0));
|
digitalWrite(strobePin, LOW);
|
||||||
|
send(cmd);
|
||||||
|
digitalWrite(strobePin, HIGH);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TM1638::sendData(byte add, byte data)
|
||||||
|
{
|
||||||
|
sendCommand(0x44);
|
||||||
|
digitalWrite(strobePin, LOW);
|
||||||
|
send(0xc0 | add);
|
||||||
|
send(data);
|
||||||
|
digitalWrite(strobePin, HIGH);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TM1638::send(byte data)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < 8; i++) {
|
||||||
|
digitalWrite(clockPin, LOW);
|
||||||
|
digitalWrite(dataPin, data & 1 ? HIGH : LOW);
|
||||||
|
data >>= 1;
|
||||||
|
digitalWrite(clockPin, HIGH);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
byte TM1638::receive()
|
||||||
|
{
|
||||||
|
byte temp = 0;
|
||||||
|
|
||||||
|
// Pull-up on
|
||||||
|
pinMode(dataPin, INPUT);
|
||||||
|
digitalWrite(dataPin, HIGH);
|
||||||
|
|
||||||
|
for (int i = 0; i < 8; i++) {
|
||||||
|
temp >>= 1;
|
||||||
|
|
||||||
|
digitalWrite(clockPin, LOW);
|
||||||
|
|
||||||
|
if (digitalRead(dataPin)) {
|
||||||
|
temp |= 0x80;
|
||||||
|
}
|
||||||
|
|
||||||
|
digitalWrite(clockPin, HIGH);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Pull-up off
|
||||||
|
pinMode(dataPin, OUTPUT);
|
||||||
|
digitalWrite(dataPin, LOW);
|
||||||
|
|
||||||
|
return temp;
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
54
TM1638.h
54
TM1638.h
@@ -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.
|
||||||
@@ -19,50 +21,50 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
#ifndef TM1638_h
|
#ifndef TM1638_h
|
||||||
#define TM1638_h
|
#define TM1638_h
|
||||||
|
|
||||||
#if defined(ARDUINO) && ARDUINO >= 100
|
#include <WProgram.h>
|
||||||
#include "Arduino.h"
|
|
||||||
#else
|
|
||||||
#include "WProgram.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "TM16XX.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
|
||||||
|
|
||||||
class TM1638 : public TM16XX
|
class TM1638
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/** Instantiate a tm1638 module specifying the display state, the starting intensity (0-7) data, clock and stobe pins. */
|
/** Instantiate a tm1638 module specifying the display state, the starting intensity (0-7) data, clock and stobe pins. */
|
||||||
TM1638(byte dataPin, byte clockPin, byte strobePin, boolean activateDisplay = true, byte intensity = 7);
|
TM1638(byte dataPin, byte clockPin, byte strobePin, boolean activateDisplay = true, byte intensity = 7);
|
||||||
|
|
||||||
/** Set the display to a unsigned hexadecimal number (with or without leading zeros) */
|
/** Set the display (segments and LEDs) active or off and intensity (range from 0-7). */
|
||||||
void setDisplayToHexNumber(unsigned long number, byte dots, boolean leadingZeros = true,
|
void setupDisplay(boolean active, byte intensity);
|
||||||
const byte numberFont[] = NUMBER_FONT);
|
|
||||||
/** Set the display to a unsigned decimal number (with or without leading zeros) */
|
/** Set the display to a unsigned hexadecimal number */
|
||||||
void setDisplayToDecNumber(unsigned long number, byte dots, boolean leadingZeros = true,
|
void setDisplayToHexNumber(unsigned long number, byte dots);
|
||||||
const byte numberFont[] = NUMBER_FONT);
|
/** Set the display to a unsigned decimal number */
|
||||||
/** Set the display to a signed decimal number (with or without leading zeros) */
|
void setDisplayToDecNumber(unsigned long number, byte dots);
|
||||||
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);
|
/** Set a single display at pos (starting at 0) to a digit (left to right) */
|
||||||
|
void setDisplayDigit(byte digit, byte pos, boolean dot);
|
||||||
|
/** Set the display to the 8 values (left to right) */
|
||||||
|
void setDisplay(const byte values[]);
|
||||||
|
|
||||||
/** 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) */
|
||||||
virtual void setLED(byte color, byte pos);
|
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). */
|
||||||
virtual byte getButtons();
|
byte getButtons();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void sendChar(byte pos, byte data, boolean dot);
|
void sendCommand(byte led);
|
||||||
void setDisplayToDecNumberAt(unsigned long number, byte dots, byte startingPos,
|
void sendData(byte add, byte data);
|
||||||
boolean leadingZeros, const byte numberFont[]);
|
void send(byte data);
|
||||||
|
byte receive();
|
||||||
|
|
||||||
|
private:
|
||||||
|
byte dataPin;
|
||||||
|
byte clockPin;
|
||||||
|
byte strobePin;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
54
TM1640.cpp
54
TM1640.cpp
@@ -1,54 +0,0 @@
|
|||||||
/*
|
|
||||||
TM1640.cpp - Library implementation for TM1640.
|
|
||||||
|
|
||||||
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 "TM1640.h"
|
|
||||||
#include "string.h"
|
|
||||||
|
|
||||||
|
|
||||||
TM1640::TM1640(byte dataPin, byte clockPin, boolean activateDisplay, byte intensity)
|
|
||||||
: TM16XX(dataPin, clockPin, dataPin, 16, activateDisplay, intensity)
|
|
||||||
{
|
|
||||||
// nothing else to do - calling super is enough
|
|
||||||
}
|
|
||||||
|
|
||||||
void TM1640::sendChar(byte pos, byte data, boolean dot)
|
|
||||||
{
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
43
TM1640.h
43
TM1640.h
@@ -1,43 +0,0 @@
|
|||||||
/*
|
|
||||||
TM1640.h - Library for TM1640.
|
|
||||||
|
|
||||||
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 TM1640_h
|
|
||||||
#define TM1640_h
|
|
||||||
|
|
||||||
#if defined(ARDUINO) && ARDUINO >= 100
|
|
||||||
#include "Arduino.h"
|
|
||||||
#else
|
|
||||||
#include "WProgram.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "TM16XX.h"
|
|
||||||
#include "TM16XXFonts.h"
|
|
||||||
|
|
||||||
class TM1640 : public TM16XX
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
/** 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);
|
|
||||||
/** Clear the display */
|
|
||||||
virtual void clearDisplay();
|
|
||||||
|
|
||||||
protected:
|
|
||||||
virtual void sendChar(byte pos, byte data, boolean dot);
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
179
TM16XX.cpp
179
TM16XX.cpp
@@ -1,179 +0,0 @@
|
|||||||
/*
|
|
||||||
TM16XX.cpp - Library implementation for TM16XX.
|
|
||||||
|
|
||||||
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 "TM16XX.h"
|
|
||||||
#include "string.h"
|
|
||||||
|
|
||||||
TM16XX::TM16XX(byte dataPin, byte clockPin, byte strobePin, byte displays, boolean activateDisplay,
|
|
||||||
byte intensity)
|
|
||||||
{
|
|
||||||
this->dataPin = dataPin;
|
|
||||||
this->clockPin = clockPin;
|
|
||||||
this->strobePin = strobePin;
|
|
||||||
this->displays = displays;
|
|
||||||
|
|
||||||
pinMode(dataPin, OUTPUT);
|
|
||||||
pinMode(clockPin, OUTPUT);
|
|
||||||
pinMode(strobePin, OUTPUT);
|
|
||||||
|
|
||||||
digitalWrite(strobePin, HIGH);
|
|
||||||
digitalWrite(clockPin, HIGH);
|
|
||||||
|
|
||||||
sendCommand(0x40);
|
|
||||||
sendCommand(0x80 | (activateDisplay ? 8 : 0) | min(7, intensity));
|
|
||||||
|
|
||||||
digitalWrite(strobePin, LOW);
|
|
||||||
send(0xC0);
|
|
||||||
for (int i = 0; i < 16; i++) {
|
|
||||||
send(0x00);
|
|
||||||
}
|
|
||||||
digitalWrite(strobePin, HIGH);
|
|
||||||
}
|
|
||||||
|
|
||||||
void TM16XX::setupDisplay(boolean active, byte 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[])
|
|
||||||
{
|
|
||||||
sendChar(pos, numberFont[digit & 0xF], dot);
|
|
||||||
}
|
|
||||||
|
|
||||||
void TM16XX::setDisplayToError()
|
|
||||||
{
|
|
||||||
setDisplay(ERROR_DATA, 8);
|
|
||||||
|
|
||||||
for (int i = 8; i < displays; i++) {
|
|
||||||
clearDisplayDigit(i, 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void TM16XX::clearDisplayDigit(byte pos, boolean dot)
|
|
||||||
{
|
|
||||||
sendChar(pos, 0, dot);
|
|
||||||
}
|
|
||||||
|
|
||||||
void TM16XX::setDisplay(const byte values[], unsigned int size)
|
|
||||||
{
|
|
||||||
for (int i = 0; i < size; i++) {
|
|
||||||
sendChar(i, values[i], 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void TM16XX::clearDisplay()
|
|
||||||
{
|
|
||||||
for (int i = 0; i < displays; i++) {
|
|
||||||
sendData(i << 1, 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void TM16XX::setDisplayToString(const char* string, const word dots, const byte pos, const byte font[])
|
|
||||||
{
|
|
||||||
for (int i = 0; i < displays - pos; i++) {
|
|
||||||
if (string[i] != '\0') {
|
|
||||||
sendChar(i + pos, font[string[i] - 32], (dots & (1 << (displays - i - 1))) != 0);
|
|
||||||
} else {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void TM16XX::setDisplayToString(const String string, const word dots, const byte pos, const byte font[])
|
|
||||||
{
|
|
||||||
int stringLength = string.length();
|
|
||||||
|
|
||||||
for (int i = 0; i < displays - pos; i++) {
|
|
||||||
if (i < stringLength) {
|
|
||||||
sendChar(i + pos, font[string.charAt(i) - 32], (dots & (1 << (displays - i - 1))) != 0);
|
|
||||||
} else {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void TM16XX::sendCommand(byte cmd)
|
|
||||||
{
|
|
||||||
digitalWrite(strobePin, LOW);
|
|
||||||
send(cmd);
|
|
||||||
digitalWrite(strobePin, HIGH);
|
|
||||||
}
|
|
||||||
|
|
||||||
void TM16XX::sendData(byte address, byte data)
|
|
||||||
{
|
|
||||||
sendCommand(0x44);
|
|
||||||
digitalWrite(strobePin, LOW);
|
|
||||||
send(0xC0 | address);
|
|
||||||
send(data);
|
|
||||||
digitalWrite(strobePin, HIGH);
|
|
||||||
}
|
|
||||||
|
|
||||||
void TM16XX::send(byte data)
|
|
||||||
{
|
|
||||||
for (int i = 0; i < 8; i++) {
|
|
||||||
digitalWrite(clockPin, LOW);
|
|
||||||
digitalWrite(dataPin, data & 1 ? HIGH : LOW);
|
|
||||||
data >>= 1;
|
|
||||||
digitalWrite(clockPin, HIGH);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
byte TM16XX::receive()
|
|
||||||
{
|
|
||||||
byte temp = 0;
|
|
||||||
|
|
||||||
// Pull-up on
|
|
||||||
pinMode(dataPin, INPUT);
|
|
||||||
digitalWrite(dataPin, HIGH);
|
|
||||||
|
|
||||||
for (int i = 0; i < 8; i++) {
|
|
||||||
temp >>= 1;
|
|
||||||
|
|
||||||
digitalWrite(clockPin, LOW);
|
|
||||||
|
|
||||||
if (digitalRead(dataPin)) {
|
|
||||||
temp |= 0x80;
|
|
||||||
}
|
|
||||||
|
|
||||||
digitalWrite(clockPin, HIGH);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Pull-up off
|
|
||||||
pinMode(dataPin, OUTPUT);
|
|
||||||
digitalWrite(dataPin, LOW);
|
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
81
TM16XX.h
81
TM16XX.h
@@ -1,81 +0,0 @@
|
|||||||
/*
|
|
||||||
TM16XX.h - Library 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/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef TM16XX_h
|
|
||||||
#define TM16XX_h
|
|
||||||
|
|
||||||
#if defined(ARDUINO) && ARDUINO >= 100
|
|
||||||
#include "Arduino.h"
|
|
||||||
#else
|
|
||||||
#include "WProgram.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "TM16XXFonts.h"
|
|
||||||
|
|
||||||
class TM16XX
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
/**
|
|
||||||
* Instantiate a tm16xx module specifying the number of displays, display state,
|
|
||||||
* the starting intensity (0-7) data, clock and stobe pins.
|
|
||||||
*/
|
|
||||||
TM16XX(byte dataPin, byte clockPin, byte strobePin, byte displays, boolean activateDisplay = true,
|
|
||||||
byte intensity = 7);
|
|
||||||
|
|
||||||
/** Set the display (segments and LEDs) active or off and intensity (range from 0-7). */
|
|
||||||
virtual void setupDisplay(boolean active, byte intensity);
|
|
||||||
|
|
||||||
/** Set a single display at pos (starting at 0) to a digit (left to right) */
|
|
||||||
virtual void setDisplayDigit(byte digit, byte pos, boolean dot, const byte numberFont[] = NUMBER_FONT);
|
|
||||||
/** Set the display to an error message */
|
|
||||||
virtual void setDisplayToError();
|
|
||||||
/** Clear a single display at pos (starting at 0, left to right) */
|
|
||||||
virtual void clearDisplayDigit(byte pos, boolean dot);
|
|
||||||
/** Set the display to the values (left to right) */
|
|
||||||
virtual void setDisplay(const byte values[], unsigned int length = 8);
|
|
||||||
/** Clear the display */
|
|
||||||
virtual void clearDisplay();
|
|
||||||
|
|
||||||
/** Set the display to the string (defaults to built in font) */
|
|
||||||
virtual void setDisplayToString(const char* string, const word dots = 0, const byte pos = 0,
|
|
||||||
const byte font[] = FONT_DEFAULT);
|
|
||||||
/** Set the display to the String (defaults to built in font) */
|
|
||||||
virtual void setDisplayToString(String string, const word dots = 0, const byte pos = 0,
|
|
||||||
const byte font[] = FONT_DEFAULT);
|
|
||||||
|
|
||||||
protected:
|
|
||||||
#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 sendData(byte add, byte data);
|
|
||||||
virtual void send(byte data);
|
|
||||||
virtual byte receive();
|
|
||||||
|
|
||||||
byte displays;
|
|
||||||
byte dataPin;
|
|
||||||
byte clockPin;
|
|
||||||
byte strobePin;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
166
TM16XXFonts.h
166
TM16XXFonts.h
@@ -1,166 +0,0 @@
|
|||||||
/*
|
|
||||||
TM16XXFonts.h - Font definition for TM16XX.
|
|
||||||
|
|
||||||
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/>.
|
|
||||||
|
|
||||||
|
|
||||||
The bits are displayed by mapping bellow
|
|
||||||
-- 0 --
|
|
||||||
| |
|
|
||||||
5 1
|
|
||||||
-- 6 --
|
|
||||||
4 2
|
|
||||||
| |
|
|
||||||
-- 3 -- .7
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef TM16XXFonts_h
|
|
||||||
#define TM16XXFonts_h
|
|
||||||
|
|
||||||
// definition for standard hexadecimal numbers
|
|
||||||
const byte NUMBER_FONT[] = {
|
|
||||||
0b00111111, // 0
|
|
||||||
0b00000110, // 1
|
|
||||||
0b01011011, // 2
|
|
||||||
0b01001111, // 3
|
|
||||||
0b01100110, // 4
|
|
||||||
0b01101101, // 5
|
|
||||||
0b01111101, // 6
|
|
||||||
0b00000111, // 7
|
|
||||||
0b01111111, // 8
|
|
||||||
0b01101111, // 9
|
|
||||||
0b01110111, // A
|
|
||||||
0b01111100, // B
|
|
||||||
0b00111001, // C
|
|
||||||
0b01011110, // D
|
|
||||||
0b01111001, // E
|
|
||||||
0b01110001 // F
|
|
||||||
};
|
|
||||||
|
|
||||||
const byte MINUS = 0b01000000;
|
|
||||||
|
|
||||||
// definition for error
|
|
||||||
const byte ERROR_DATA[] = {
|
|
||||||
0b01111001, // E
|
|
||||||
0b01010000, // r
|
|
||||||
0b01010000, // r
|
|
||||||
0b01011100, // o
|
|
||||||
0b01010000, // r
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0
|
|
||||||
};
|
|
||||||
|
|
||||||
// definition for the displayable ASCII chars
|
|
||||||
const byte FONT_DEFAULT[] = {
|
|
||||||
0b00000000, // (32) <space>
|
|
||||||
0b10000110, // (33) !
|
|
||||||
0b00100010, // (34) "
|
|
||||||
0b01111110, // (35) #
|
|
||||||
0b01101101, // (36) $
|
|
||||||
0b00000000, // (37) %
|
|
||||||
0b00000000, // (38) &
|
|
||||||
0b00000010, // (39) '
|
|
||||||
0b00110000, // (40) (
|
|
||||||
0b00000110, // (41) )
|
|
||||||
0b01100011, // (42) *
|
|
||||||
0b00000000, // (43) +
|
|
||||||
0b00000100, // (44) ,
|
|
||||||
0b01000000, // (45) -
|
|
||||||
0b10000000, // (46) .
|
|
||||||
0b01010010, // (47) /
|
|
||||||
0b00111111, // (48) 0
|
|
||||||
0b00000110, // (49) 1
|
|
||||||
0b01011011, // (50) 2
|
|
||||||
0b01001111, // (51) 3
|
|
||||||
0b01100110, // (52) 4
|
|
||||||
0b01101101, // (53) 5
|
|
||||||
0b01111101, // (54) 6
|
|
||||||
0b00100111, // (55) 7
|
|
||||||
0b01111111, // (56) 8
|
|
||||||
0b01101111, // (57) 9
|
|
||||||
0b00000000, // (58) :
|
|
||||||
0b00000000, // (59) ;
|
|
||||||
0b00000000, // (60) <
|
|
||||||
0b01001000, // (61) =
|
|
||||||
0b00000000, // (62) >
|
|
||||||
0b01010011, // (63) ?
|
|
||||||
0b01011111, // (64) @
|
|
||||||
0b01110111, // (65) A
|
|
||||||
0b01111111, // (66) B
|
|
||||||
0b00111001, // (67) C
|
|
||||||
0b00111111, // (68) D
|
|
||||||
0b01111001, // (69) E
|
|
||||||
0b01110001, // (70) F
|
|
||||||
0b00111101, // (71) G
|
|
||||||
0b01110110, // (72) H
|
|
||||||
0b00000110, // (73) I
|
|
||||||
0b00011111, // (74) J
|
|
||||||
0b01101001, // (75) K
|
|
||||||
0b00111000, // (76) L
|
|
||||||
0b00010101, // (77) M
|
|
||||||
0b00110111, // (78) N
|
|
||||||
0b00111111, // (79) O
|
|
||||||
0b01110011, // (80) P
|
|
||||||
0b01100111, // (81) Q
|
|
||||||
0b00110001, // (82) R
|
|
||||||
0b01101101, // (83) S
|
|
||||||
0b01111000, // (84) T
|
|
||||||
0b00111110, // (85) U
|
|
||||||
0b00101010, // (86) V
|
|
||||||
0b00011101, // (87) W
|
|
||||||
0b01110110, // (88) X
|
|
||||||
0b01101110, // (89) Y
|
|
||||||
0b01011011, // (90) Z
|
|
||||||
0b00111001, // (91) [
|
|
||||||
0b01100100, // (92) \ (this can't be the last char on a line, even in comment or it'll concat)
|
|
||||||
0b00001111, // (93) ]
|
|
||||||
0b00000000, // (94) ^
|
|
||||||
0b00001000, // (95) _
|
|
||||||
0b00100000, // (96) `
|
|
||||||
0b01011111, // (97) a
|
|
||||||
0b01111100, // (98) b
|
|
||||||
0b01011000, // (99) c
|
|
||||||
0b01011110, // (100) d
|
|
||||||
0b01111011, // (101) e
|
|
||||||
0b00110001, // (102) f
|
|
||||||
0b01101111, // (103) g
|
|
||||||
0b01110100, // (104) h
|
|
||||||
0b00000100, // (105) i
|
|
||||||
0b00001110, // (106) j
|
|
||||||
0b01110101, // (107) k
|
|
||||||
0b00110000, // (108) l
|
|
||||||
0b01010101, // (109) m
|
|
||||||
0b01010100, // (110) n
|
|
||||||
0b01011100, // (111) o
|
|
||||||
0b01110011, // (112) p
|
|
||||||
0b01100111, // (113) q
|
|
||||||
0b01010000, // (114) r
|
|
||||||
0b01101101, // (115) s
|
|
||||||
0b01111000, // (116) t
|
|
||||||
0b00011100, // (117) u
|
|
||||||
0b00101010, // (118) v
|
|
||||||
0b00011101, // (119) w
|
|
||||||
0b01110110, // (120) x
|
|
||||||
0b01101110, // (121) y
|
|
||||||
0b01000111, // (122) z
|
|
||||||
0b01000110, // (123) {
|
|
||||||
0b00000110, // (124) |
|
|
||||||
0b01110000, // (125) }
|
|
||||||
0b00000001, // (126) ~
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,102 +0,0 @@
|
|||||||
/*
|
|
||||||
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]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
/*
|
|
||||||
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>
|
|
||||||
|
|
||||||
// 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
|
|
||||||
module.setDisplayToHexNumber(0x1234ABCD, 0xF0);
|
|
||||||
}
|
|
||||||
|
|
||||||
void loop() {
|
|
||||||
byte keys = module.getButtons();
|
|
||||||
|
|
||||||
// light the first 4 red LEDs and the last 4 green LEDs as the buttons are pressed
|
|
||||||
module.setLEDs(((keys & 0xF0) << 8) | (keys & 0xF));
|
|
||||||
}
|
|
||||||
@@ -1,56 +0,0 @@
|
|||||||
/*
|
|
||||||
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>
|
|
||||||
|
|
||||||
#define MODULES 4
|
|
||||||
|
|
||||||
// define a modules
|
|
||||||
TM1638 modules[] = {
|
|
||||||
TM1638(8, 9, 7),
|
|
||||||
TM1638(8, 9, 6),
|
|
||||||
TM1638(8, 9, 5),
|
|
||||||
TM1638(8, 9, 4)
|
|
||||||
};
|
|
||||||
|
|
||||||
void setup() {
|
|
||||||
}
|
|
||||||
|
|
||||||
const char string[] = " SEE LIBRARY PROJECT AT CODE.GOOGLE.COM ";
|
|
||||||
int base = 0;
|
|
||||||
|
|
||||||
void loop() {
|
|
||||||
for (int i = 0; i < MODULES; i++) {
|
|
||||||
const char* pos = string + base + (i * 8);
|
|
||||||
|
|
||||||
if (pos >= string && pos + 8 < string + sizeof(string)) {
|
|
||||||
modules[i].setDisplayToString(pos);
|
|
||||||
} else {
|
|
||||||
modules[i].clearDisplay();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
base++;
|
|
||||||
|
|
||||||
if (base == sizeof(string) - 8) {
|
|
||||||
base = -MODULES * 8;
|
|
||||||
}
|
|
||||||
|
|
||||||
delay(100);
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,101 +0,0 @@
|
|||||||
/*
|
|
||||||
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"
|
|
||||||
|
|
||||||
// hello segments for display
|
|
||||||
const byte hello[] = {
|
|
||||||
0b00000000, 0b01110110, 0b01111001, 0b00111000, 0b00111000, 0b00111111, 0b00000000, 0b00000000
|
|
||||||
};
|
|
||||||
|
|
||||||
// define the first module
|
|
||||||
TM1638 module1(8, 9, 7);
|
|
||||||
// to chain modules, use the same clk and data - just specify a different strobe pin
|
|
||||||
TM1638 module2(8, 9, 6);
|
|
||||||
|
|
||||||
unsigned long value = 0L;
|
|
||||||
boolean state = true;
|
|
||||||
|
|
||||||
void setup()
|
|
||||||
{
|
|
||||||
// display the hello segments on module 1
|
|
||||||
module1.setDisplay(hello);
|
|
||||||
// display the hello segments on module 2
|
|
||||||
module2.setDisplay(hello);
|
|
||||||
|
|
||||||
// light the lower 5 red LEDs and the top 5 green LEDs
|
|
||||||
module1.setLEDs(0b00011111 | 0b11111000 << 8);
|
|
||||||
|
|
||||||
// light the 3rd red LED
|
|
||||||
module2.setLED(TM1638_COLOR_RED, 3);
|
|
||||||
// light the 5th green LED
|
|
||||||
module2.setLED(TM1638_COLOR_GREEN, 5);
|
|
||||||
// light the 7th red and green LEDs
|
|
||||||
module2.setLED(TM1638_COLOR_RED | TM1638_COLOR_GREEN, 7);
|
|
||||||
}
|
|
||||||
|
|
||||||
void loop()
|
|
||||||
{
|
|
||||||
byte key1, key2;
|
|
||||||
|
|
||||||
// read the buttons from the first module
|
|
||||||
key1 = module1.getButtons();
|
|
||||||
// read the buttons from the second module
|
|
||||||
key2 = module2.getButtons();
|
|
||||||
|
|
||||||
// both pressed
|
|
||||||
if (key1 != 0 && key2 != 0) {
|
|
||||||
value = 0;
|
|
||||||
|
|
||||||
// set the display to 0 on both modules if they have buttons pressed simultaneously
|
|
||||||
module1.setDisplayToHexNumber(value, 0b10101010);
|
|
||||||
module2.setDisplayToDecNumber(value, 0b01010101);
|
|
||||||
} else {
|
|
||||||
// check the first module buttons
|
|
||||||
if (key1 != 0) {
|
|
||||||
// show the pressed buttons of the first module on its display
|
|
||||||
module2.setDisplayToBinNumber(key1, 0);
|
|
||||||
// and on the LEDs
|
|
||||||
module1.setLEDs(key1);
|
|
||||||
|
|
||||||
// check to see if it's the last button pressed
|
|
||||||
if (key1 & 128) {
|
|
||||||
// toggle the display state on/off
|
|
||||||
state = !state;
|
|
||||||
delay(200); // just wait for button up
|
|
||||||
}
|
|
||||||
|
|
||||||
// set the intensity and display state
|
|
||||||
module1.setupDisplay(state, key1 >> 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
// check the second module buttons
|
|
||||||
if (key2 != 0) {
|
|
||||||
// just add it to the display value
|
|
||||||
value += key2;
|
|
||||||
|
|
||||||
// display it as an hexadecimal on the first module
|
|
||||||
module1.setDisplayToHexNumber(value, 0b10101010);
|
|
||||||
// and as a decimal on the second module
|
|
||||||
module2.setDisplayToDecNumber(value, 0b01010101);
|
|
||||||
|
|
||||||
// light the LEDs
|
|
||||||
module2.setLEDs(key2 << 8);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,36 +0,0 @@
|
|||||||
/*
|
|
||||||
Library examples for TM1640.
|
|
||||||
|
|
||||||
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> // required because the way arduino deals with libraries
|
|
||||||
#include <TM1640.h>
|
|
||||||
|
|
||||||
// define a module on data pin 3, clock pin 2
|
|
||||||
TM1640 module(3, 2);
|
|
||||||
|
|
||||||
void setup()
|
|
||||||
{
|
|
||||||
// nothing to do here
|
|
||||||
}
|
|
||||||
|
|
||||||
void loop()
|
|
||||||
{
|
|
||||||
char text[17];
|
|
||||||
|
|
||||||
sprintf(text, "testing %u", millis());
|
|
||||||
|
|
||||||
module.setDisplayToString(text);
|
|
||||||
}
|
|
||||||
30
keywords.txt
30
keywords.txt
@@ -6,34 +6,20 @@
|
|||||||
# Datatypes (KEYWORD1)
|
# Datatypes (KEYWORD1)
|
||||||
#######################################
|
#######################################
|
||||||
|
|
||||||
TM16XX KEYWORD1
|
TM1638 KEYWORD1
|
||||||
TM1638 KEYWORD1
|
|
||||||
TM1640 KEYWORD1
|
|
||||||
InvertedTM1638 KEYWORD1
|
|
||||||
|
|
||||||
#######################################
|
#######################################
|
||||||
# Methods and Functions (KEYWORD2)
|
# Methods and Functions (KEYWORD2)
|
||||||
#######################################
|
#######################################
|
||||||
|
|
||||||
setupDisplay KEYWORD2
|
setSegments KEYWORD2
|
||||||
setDisplayToHexNumber KEYWORD2
|
setLEDs KEYWORD2
|
||||||
setDisplayToDecNumber KEYWORD2
|
getButtons KEYWORD2
|
||||||
setDisplayToBinNumber KEYWORD2
|
sendCommand KEYWORD2
|
||||||
setDisplayDigit KEYWORD2
|
sendData KEYWORD2
|
||||||
setDisplay KEYWORD2
|
send KEYWORD2
|
||||||
clearDisplay KEYWORD2
|
receive KEYWORD2
|
||||||
setDisplayToString KEYWORD2
|
|
||||||
setLED KEYWORD2
|
|
||||||
setLEDs KEYWORD2
|
|
||||||
getButtons KEYWORD2
|
|
||||||
sendCommand KEYWORD2
|
|
||||||
sendData KEYWORD2
|
|
||||||
sendChar KEYWORD2
|
|
||||||
send KEYWORD2
|
|
||||||
receive KEYWORD2
|
|
||||||
|
|
||||||
#######################################
|
#######################################
|
||||||
# Constants (LITERAL1)
|
# Constants (LITERAL1)
|
||||||
#######################################
|
#######################################
|
||||||
TM1638_COLOR_RED LITERAL1
|
|
||||||
TM1638_COLOR_GREEN LITERAL1
|
|
||||||
|
|||||||
63
tm1638_lib.pde
Normal file
63
tm1638_lib.pde
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
#include "TM1638.h"
|
||||||
|
|
||||||
|
unsigned char hello[] = {
|
||||||
|
0b00000000, 0b01110110, 0b01111001, 0b00111000, 0b00111000, 0b00111111, 0b00000000, 0b00000000
|
||||||
|
};
|
||||||
|
|
||||||
|
TM1638 module1(2, 3, 4);
|
||||||
|
TM1638 module2(2, 3, 5);
|
||||||
|
unsigned long value = 0L;
|
||||||
|
boolean state = true;
|
||||||
|
|
||||||
|
void setup()
|
||||||
|
{
|
||||||
|
module1.setDisplay(hello);
|
||||||
|
module2.setDisplay(hello);
|
||||||
|
|
||||||
|
module1.setLEDs(0b00011111 | 0b11111000 << 8);
|
||||||
|
|
||||||
|
module2.setLED(TM1638_COLOR_RED, 3);
|
||||||
|
module2.setLED(TM1638_COLOR_GREEN, 5);
|
||||||
|
module2.setLED(TM1638_COLOR_RED | TM1638_COLOR_GREEN, 7);
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop()
|
||||||
|
{
|
||||||
|
byte key1, key2;
|
||||||
|
|
||||||
|
key1 = module1.getButtons();
|
||||||
|
key2 = module2.getButtons();
|
||||||
|
|
||||||
|
// both pressed
|
||||||
|
if (key1 != 0 && key2 != 0) {
|
||||||
|
value = 0;
|
||||||
|
|
||||||
|
module1.setDisplayToHexNumber(value, 0b10101010);
|
||||||
|
module2.setDisplayToDecNumber(value, 0b01010101);
|
||||||
|
} else {
|
||||||
|
if (key1 != 0) {
|
||||||
|
value += key1;
|
||||||
|
|
||||||
|
module2.setDisplayToBinNumber(key1, 0);
|
||||||
|
|
||||||
|
module1.setLEDs(key1);
|
||||||
|
|
||||||
|
if (key1 & 128) {
|
||||||
|
state = !state;
|
||||||
|
delay(200); // just wait for button up
|
||||||
|
}
|
||||||
|
|
||||||
|
module1.setupDisplay(state, key1 >> 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (key2 != 0) {
|
||||||
|
value += key2;
|
||||||
|
|
||||||
|
module1.setDisplayToHexNumber(value, 0b10101010);
|
||||||
|
module2.setDisplayToDecNumber(value, 0b01010101);
|
||||||
|
|
||||||
|
module2.setLEDs(key2 << 8);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Reference in New Issue
Block a user