When I was browsing various web sites to see what electronic components to buy one day I noticed some interesting little kits comprising of switches, LEDs and a couple of 4 digit seven segment displays saw I decided to purchase one, the first thing I noticed was at the heart of the module was a chip called a TM1638, never heard of it. A quick search dug up links to the datasheet (link supplied underneath in the links section) and an arduino library (in the code section). That makes life easier.
The module I bought had 5 connections.
VCC – 5v from Arduino
Gnd – GND from Arduino
STB – strobe pin, an output from your Arduino
CLK – clock pin, an output from your Arduino
DIO – data pin, another ouput from your Arduino
Layout
Code
You can get a library to make development easier from https://github.com/rjbatista/tm1638-library
This is a test example
[codesyntax lang=”cpp”]
#include <TM1638.h> #include <TM1638QYF.h> TM1638QYF module(8,9,10); word mode; unsigned long startTime; void setup() { startTime = millis(); module.setupDisplay(true, 7); mode = 0; } void update(TM1638QYF* module, word* mode) { word buttons = module->getButtons(); unsigned long runningSecs = (millis() - startTime) / 1000; // button pressed - change mode if (buttons != 0) { *mode = buttons >> 1; if (*mode < 128) { module->clearDisplay(); delay(100); } } switch (*mode) { case 0: module->setDisplayToDecNumber(runningSecs, 1 << 6); break; case 1: module->setDisplayToDecNumber(runningSecs, 1 << 5, false); break; case 2: module->setDisplayToHexNumber(runningSecs, 1 << 4); break; case 4: module->setDisplayToHexNumber(runningSecs, 1 << 3, false); break; case 8: module->setDisplayToBinNumber(runningSecs, 1 << 2); break; case 16: char s[9]; sprintf(s, "Secs %03d", runningSecs % 999); module->setDisplayToString(s, 1 << 1); break; case 32: if (runningSecs % 2 == 0) { module->setDisplayToString("TM1638QY", 1); } else { module->setDisplayToString(String("LIBRARY "), 1); } break; case 64: module->setDisplayToError(); break; case 128: module->setDisplayToDecNumber(*mode, 0); break; case 256: module->setDisplayToString("ABCDE", 1 << (runningSecs % 8)); break; default: module->setDisplayToBinNumber(buttons & 0xF, buttons >> 8); } } void loop() { update(&module, &mode); }
[/codesyntax]
Links
TM1638 English datasheet