Arduino - Compatible 8X Seven Segments Display
Z MediaWiki SPŠ a VOŠ Písek
(Rozdíly mezi verzemi)
JA (diskuse | příspěvky)
(Založena nová stránka: Integrovaná tlačítka, LED & 7 segmentový display - Vyžaduje pouze 3 IO výstupy k činnosti - TM1638 chip micro-8 8-segment LED displayů a 8 tlačítek a 8 testova...)
(Založena nová stránka: Integrovaná tlačítka, LED & 7 segmentový display - Vyžaduje pouze 3 IO výstupy k činnosti - TM1638 chip micro-8 8-segment LED displayů a 8 tlačítek a 8 testova...)
Aktuální verze z 30. 12. 2012, 12:32
Integrovaná tlačítka, LED & 7 segmentový display - Vyžaduje pouze 3 IO výstupy k činnosti - TM1638 chip micro-8 8-segment LED displayů a 8 tlačítek a 8 testovacíhc dvoubarevných Led kontrolek, IO zajišťují sériovou komunikaci rozhraní, 8 nastavovacích úrovní jasu. Specifikace: 0.2 cm x 5.0 cm x 1.0 cm
Programuje se v progamu Arduino pomoc jazyka C++ (možno sáhnout zde http://arduino.cc/en/Main/Software). V programu Arduino můžete také načíst funkční příklady z knihovny (možno stáhnout zde http://code.google.com/p/tm1638-library/)
Příklad pro funkční modul
#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]); } }
Jednoduchý příklad pro jedno Arduino
#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)); }