
TM1638 LED 7-Segmentanzeigen und Taster am Arduino
Im Artikel China Post – Arduino Multi Function Shield hatte ich bereits ein Arduino Shield mit LED-Anzeigen vorgestellt.
Eine weitere Möglichkeit am Arduino 7-Segment Anzeigen zu betreiben ist der IC TM1638.
Der TM1638 kann 10 Stellen 7-Segment Anzeige und ein 3 x 8 Tastenfeld steuern. In der Praxis wird oft weniger umgesetzt. Die hier beschriebene Platine steuert 8x 7-Segment Anzeigen, 8x LED und 8x Taster an. Für die Ansteuerung sind nur 3 Digital Pins am Arduino erforderlich.Es ist kein Shield, welches für die Montage praktischer wäre. Mit 5 Kabeln ist aber auch die Verdrahtung kein Problem und die restlichen Pins sind ohne Einschränkung nutzbar.
Die Kommunikation ist nicht so trivial wie eine LED-Ansteuerung per Schieberegister. Daher greift man am einfachsten auf die TM1638 Bibliothek von Rjbatista zurück.
https://github.com/rjbatista/tm1638-library
Funktionen des Testprogramm tm1638_functions_example
- führende Nullen
- ohne führende Nullen, Dezimalpunk
- führende Nullen, hexadezimal
- ohne führende Nullen, hexadezimal
- binär
- Durchzählen der Digits
- 4 Digit Text + 4 Digit Ziffern
- wechselnder Text
Weitere Beispielprogramme zeigen die Anwendung von Lauftext und die Ansteuerung einzelner LED’s.
Es können auch Taster gleichzeitig gedrückt werden.
Es gibt neben dieser Platine noch weitere Ausführungen mit mehr Tastern , bzw. als kaskadierbare Anzeige.
Der Preis für Module mit dem TM1638 beginnt bei 5€.
[code language=”Arduino” title=”tm1638_functions_example”]
/*
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 1
// define a regular module and a inverted module
// TM1638 module1(DIO, CLC, STB);
TM1638 module1(51, 52, 53);
TM1638* modules[NO_MODULES] = {
&module1,
};
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]);
}
}
[/code]