Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c327bf715a | ||
|
|
1716fddf4a | ||
|
|
f54360bd37 |
12
README.txt
12
README.txt
@@ -8,13 +8,19 @@ A library for interacting an arduino with a tm1638.
|
|||||||
|
|
||||||
Includes:
|
Includes:
|
||||||
- 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; Reading
|
- Support for multiple chained tm1638;
|
||||||
- simultaneous button presses.
|
- Reading simultaneous button presses;
|
||||||
|
- Support for dimming the display and LEDs;
|
||||||
|
- Support for writing text.
|
||||||
|
|
||||||
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
|
||||||
|
|
||||||
|
|
||||||
|
USAGE NOTES
|
||||||
|
-----------
|
||||||
|
|
||||||
|
Just put the files on a TM1638 directory under "arduino/libraries" on your instalation
|
||||||
|
|
||||||
|
|
||||||
PROJECT HOME
|
PROJECT HOME
|
||||||
------------
|
------------
|
||||||
|
|||||||
54
TM1638.cpp
54
TM1638.cpp
@@ -21,46 +21,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
#include "WProgram.h"
|
#include "WProgram.h"
|
||||||
#include "TM1638.h"
|
#include "TM1638.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)
|
||||||
{
|
{
|
||||||
this->dataPin = dataPin;
|
this->dataPin = dataPin;
|
||||||
@@ -134,6 +94,20 @@ void TM1638::setDisplay(const byte values[])
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TM1638::clearDisplay()
|
||||||
|
{
|
||||||
|
for (int i = 0; i < 8; i++) {
|
||||||
|
sendData(i << 1, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void TM1638::setDisplayToString(const char* string, const byte font[])
|
||||||
|
{
|
||||||
|
for (int i = 0; i < 8; i++) {
|
||||||
|
sendData(i << 1, font[string[i] - 32]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void TM1638::setLED(byte color, byte pos)
|
void TM1638::setLED(byte color, byte pos)
|
||||||
{
|
{
|
||||||
sendData((pos << 1) + 1, color);
|
sendData((pos << 1) + 1, color);
|
||||||
|
|||||||
5
TM1638.h
5
TM1638.h
@@ -22,6 +22,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
#define TM1638_h
|
#define TM1638_h
|
||||||
|
|
||||||
#include <WProgram.h>
|
#include <WProgram.h>
|
||||||
|
#include "TM1638Fonts.h"
|
||||||
|
|
||||||
#define TM1638_COLOR_RED 1
|
#define TM1638_COLOR_RED 1
|
||||||
#define TM1638_COLOR_GREEN 2
|
#define TM1638_COLOR_GREEN 2
|
||||||
@@ -45,6 +46,10 @@ class TM1638
|
|||||||
void setDisplayDigit(byte digit, byte pos, boolean dot);
|
void setDisplayDigit(byte digit, byte pos, boolean dot);
|
||||||
/** Set the display to the 8 values (left to right) */
|
/** Set the display to the 8 values (left to right) */
|
||||||
void setDisplay(const byte values[]);
|
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);
|
||||||
|
|
||||||
/** 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);
|
||||||
|
|||||||
166
TM1638Fonts.h
Normal file
166
TM1638Fonts.h
Normal file
@@ -0,0 +1,166 @@
|
|||||||
|
/*
|
||||||
|
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.
|
||||||
|
|
||||||
|
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 TM1638Fonts_h
|
||||||
|
#define TM1638Fonts_h
|
||||||
|
|
||||||
|
// definition for standard hexadecimal numbers
|
||||||
|
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
|
||||||
|
};
|
||||||
|
|
||||||
|
// definition for error
|
||||||
|
const byte ERROR[] = {
|
||||||
|
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) )
|
||||||
|
0b00000000, // (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
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
/*
|
||||||
|
TM1638.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/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <TM1638.h>
|
||||||
|
|
||||||
|
// define a module on data pin 3, clock pin 2 and strobe pin 4
|
||||||
|
TM1638 module(3, 2, 4);
|
||||||
|
|
||||||
|
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));
|
||||||
|
}
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
/*
|
||||||
|
TM1638.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/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <TM1638.h>
|
||||||
|
|
||||||
|
#define MODULES 4
|
||||||
|
|
||||||
|
// define a modules
|
||||||
|
TM1638 modules[] = {
|
||||||
|
TM1638(3, 2, 4),
|
||||||
|
TM1638(3, 2, 5),
|
||||||
|
TM1638(3, 2, 6),
|
||||||
|
TM1638(3, 2, 7)
|
||||||
|
};
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,101 @@
|
|||||||
|
/*
|
||||||
|
TM1638.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/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "TM1638.h"
|
||||||
|
|
||||||
|
// hello segments for display
|
||||||
|
const byte hello[] = {
|
||||||
|
0b00000000, 0b01110110, 0b01111001, 0b00111000, 0b00111000, 0b00111111, 0b00000000, 0b00000000
|
||||||
|
};
|
||||||
|
|
||||||
|
// define the first module
|
||||||
|
TM1638 module1(3, 2, 4);
|
||||||
|
// to chain modules, use the same clk and data - just specify a different strobe pin
|
||||||
|
TM1638 module2(3, 2, 5);
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
12
keywords.txt
12
keywords.txt
@@ -12,7 +12,15 @@ TM1638 KEYWORD1
|
|||||||
# Methods and Functions (KEYWORD2)
|
# Methods and Functions (KEYWORD2)
|
||||||
#######################################
|
#######################################
|
||||||
|
|
||||||
setSegments KEYWORD2
|
setupDisplay KEYWORD2
|
||||||
|
setDisplayToHexNumber KEYWORD2
|
||||||
|
setDisplayToDecNumber KEYWORD2
|
||||||
|
setDisplayToBinNumber KEYWORD2
|
||||||
|
setDisplayDigit KEYWORD2
|
||||||
|
setDisplay KEYWORD2
|
||||||
|
clearDisplay KEYWORD2
|
||||||
|
setDisplayToString KEYWORD2
|
||||||
|
setLED KEYWORD2
|
||||||
setLEDs KEYWORD2
|
setLEDs KEYWORD2
|
||||||
getButtons KEYWORD2
|
getButtons KEYWORD2
|
||||||
sendCommand KEYWORD2
|
sendCommand KEYWORD2
|
||||||
@@ -23,3 +31,5 @@ receive KEYWORD2
|
|||||||
#######################################
|
#######################################
|
||||||
# Constants (LITERAL1)
|
# Constants (LITERAL1)
|
||||||
#######################################
|
#######################################
|
||||||
|
TM1638_COLOR_RED LITERAL1
|
||||||
|
TM1638_COLOR_GREEN LITERAL1
|
||||||
|
|||||||
@@ -1,63 +0,0 @@
|
|||||||
#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