diff --git a/README.md b/README.md index 403028a..cc18df7 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ Arduino library for TM1637 (LED Driver) Description ----------- -An Arduino library for 7-segment display modules based on the TM1637 chip, such as Seeed Studio's [Grove 4 digit display](http://www.seeedstudio.com/depot/grove-4digit-display-p-1198.html). The TM1637 chip also has keyboard input capability, but it's not implemented in this library. +An Arduino library for 7-segment display modules based on the TM1637 chip, such as Seeed Studio's [Grove 4 digit display](http://www.seeedstudio.com/depot/grove-4digit-display-p-1198.html), as well as for discrete TM1637 assemblies, like drawn in the manual (see docs). The TM1637 chip also has keyboard input capability, and it's now implemented in this library. Hardware Connection ------------------- @@ -23,5 +23,7 @@ The library provides a single class named TM1637Display. An instance of this cla * `showNumberDec` - Display a decimal number * `showNumberDecEx` - Display a decimal number with decimal points or colon * `setBrightness` - Sets the brightness of the display +* `getKeyCode` - Read the Keypad and returns a value 0-16, where 0 means 'no key' +* `lastKeyCode` - Returns the last read key (read during last setSegments or getKeyCode) and returns a value 0-16, where 0 means 'no key' The information given above is only a summary. Please refer to TM1637Display.h for more information. An example is included, demonstrating the operation of most of the functions. diff --git a/TM1637Display.cpp b/TM1637Display.cpp index 2f45f19..f702032 100644 --- a/TM1637Display.cpp +++ b/TM1637Display.cpp @@ -1,5 +1,5 @@ - // Author: avishorp@gmail.com +// Extended to 6 digits and key-scan: Guido Dampf // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public @@ -27,6 +27,7 @@ extern "C" { #define TM1637_I2C_COMM1 0x40 #define TM1637_I2C_COMM2 0xC0 #define TM1637_I2C_COMM3 0x80 +#define TM1637_I2C_COMM4 0x42 // // A @@ -37,7 +38,7 @@ extern "C" { // --- // D const uint8_t digitToSegment[] = { - // XGFEDCBA + // XGFEDCBA 0b00111111, // 0 0b00000110, // 1 0b01011011, // 2 @@ -54,131 +55,163 @@ const uint8_t digitToSegment[] = { 0b01011110, // d 0b01111001, // E 0b01110001 // F - }; +}; static const uint8_t minusSegments = 0b01000000; -TM1637Display::TM1637Display(uint8_t pinClk, uint8_t pinDIO, unsigned int bitDelay) +TM1637Display::TM1637Display(uint8_t pinClk, uint8_t pinDIO, unsigned int bitDelay, uint8_t noDigits) { - // Copy the pin numbers - m_pinClk = pinClk; - m_pinDIO = pinDIO; - m_bitDelay = bitDelay; - - // Set the pin direction and default value. - // Both pins are set as inputs, allowing the pull-up resistors to pull them up - pinMode(m_pinClk, INPUT); - pinMode(m_pinDIO,INPUT); - digitalWrite(m_pinClk, LOW); - digitalWrite(m_pinDIO, LOW); + // Copy the pin numbers + m_pinClk = pinClk; + m_pinDIO = pinDIO; + m_bitDelay = bitDelay; + m_noDigits = noDigits; + + // Set the pin direction and default value. + // Both pins are set as inputs, allowing the pull-up resistors to pull them up + pinMode(m_pinClk, INPUT); + pinMode(m_pinDIO,INPUT); + digitalWrite(m_pinClk, LOW); + digitalWrite(m_pinDIO, LOW); } void TM1637Display::setBrightness(uint8_t brightness, bool on) { - m_brightness = (brightness & 0x7) | (on? 0x08 : 0x00); + m_brightness = (brightness & 0x7) | (on? 0x08 : 0x00); } void TM1637Display::setSegments(const uint8_t segments[], uint8_t length, uint8_t pos) { - // Write COMM1 - start(); - writeByte(TM1637_I2C_COMM1); - stop(); - - // Write COMM2 + first digit address - start(); - writeByte(TM1637_I2C_COMM2 + (pos & 0x03)); - - // Write the data bytes - for (uint8_t k=0; k < length; k++) - writeByte(segments[k]); - - stop(); + if (length==0) length = m_noDigits; + // Write COMM1 + start(); + if (writeByte(TM1637_I2C_COMM1)) + { + stop(); + return; + } + stop(); + + // Write COMM2 + first digit address + start(); + if (pos > 5) pos &= 0x03; + if (writeByte(TM1637_I2C_COMM2 + pos)) + { + stop(); + return; + } - // Write COMM3 + brightness - start(); - writeByte(TM1637_I2C_COMM3 + (m_brightness & 0x0f)); - stop(); + // Write the data bytes + for (uint8_t k=0; k < length; k++) + if(writeByte(segments[k])) + { + stop(); + return; + } + stop(); + + // Write COMM3 + brightness + start(); + if (writeByte(TM1637_I2C_COMM3 + (m_brightness & 0x0f))) + { + stop(); + return; + } + stop(); + + // Write COMM4 + start(); + if (writeByte(TM1637_I2C_COMM4)) + { + stop(); + return; + } + m_KeyCode = readByte(); + stop(); } void TM1637Display::clear() { - uint8_t data[] = { 0, 0, 0, 0 }; - setSegments(data); + uint8_t data[] = { 0, 0, 0, 0, 0, 0 }; + setSegments(data); } -void TM1637Display::showNumberDec(int num, bool leading_zero, uint8_t length, uint8_t pos) +void TM1637Display::showNumberDec(long num, bool leading_zero, uint8_t length, uint8_t pos) { + if (length==0) length = m_noDigits; showNumberDecEx(num, 0, leading_zero, length, pos); } -void TM1637Display::showNumberDecEx(int num, uint8_t dots, bool leading_zero, +void TM1637Display::showNumberDecEx(long num, uint8_t dots, bool leading_zero, uint8_t length, uint8_t pos) { + if (length==0) length = m_noDigits; showNumberBaseEx(num < 0? -10 : 10, num < 0? -num : num, dots, leading_zero, length, pos); } void TM1637Display::showNumberHexEx(uint16_t num, uint8_t dots, bool leading_zero, uint8_t length, uint8_t pos) { + if (length==0) length = m_noDigits; showNumberBaseEx(16, num, dots, leading_zero, length, pos); } -void TM1637Display::showNumberBaseEx(int8_t base, uint16_t num, uint8_t dots, bool leading_zero, - uint8_t length, uint8_t pos) +void TM1637Display::showNumberBaseEx(int8_t base, uint32_t num, uint8_t dots, bool leading_zero, + uint8_t length, uint8_t pos) { - bool negative = false; - if (base < 0) { - base = -base; - negative = true; - } - - - uint8_t digits[4]; - - if (num == 0 && !leading_zero) { - // Singular case - take care separately - for(uint8_t i = 0; i < (length-1); i++) - digits[i] = 0; - digits[length-1] = encodeDigit(0); - } - else { - //uint8_t i = length-1; - //if (negative) { - // // Negative number, show the minus sign - // digits[i] = minusSegments; - // i--; - //} - - for(int i = length-1; i >= 0; --i) - { - uint8_t digit = num % base; - - if (digit == 0 && num == 0 && leading_zero == false) - // Leading zero is blank - digits[i] = 0; - else - digits[i] = encodeDigit(digit); - - if (digit == 0 && num == 0 && negative) { - digits[i] = minusSegments; - negative = false; - } - - num /= base; - } - - if(dots != 0) - { - showDots(dots, digits); - } + if (length==0) length = m_noDigits; + bool negative = false; + if (base < 0) { + base = -base; + negative = true; + } + + + uint8_t digits[6]; + + if (num == 0 && !leading_zero) { + // Singular case - take care separately + for(uint8_t i = 0; i < (length-1); i++) + digits[i] = 0; + digits[length-1] = encodeDigit(0); + } + else { + //uint8_t i = length-1; + //if (negative) { + // // Negative number, show the minus sign + // digits[i] = minusSegments; + // i--; + //} + + for(int i = length-1; i >= 0; --i) + { + uint8_t digit = num % base; + + if (digit == 0 && num == 0 && leading_zero == false) + // Leading zero is blank + digits[i] = 0; + else + digits[i] = encodeDigit(digit); + + if (digit == 0 && num == 0 && negative) { + digits[i] = minusSegments; + negative = false; + } + + num /= base; + } + + if(dots != 0) + { + showDots(dots, digits); } - setSegments(digits, length, pos); + } + setSegments(digits, length, pos); } void TM1637Display::bitDelay() { - delayMicroseconds(m_bitDelay); + delayMicroseconds(m_bitDelay); } void TM1637Display::start() @@ -189,12 +222,16 @@ void TM1637Display::start() void TM1637Display::stop() { - pinMode(m_pinDIO, OUTPUT); - bitDelay(); - pinMode(m_pinClk, INPUT); - bitDelay(); - pinMode(m_pinDIO, INPUT); - bitDelay(); + pinMode(m_pinDIO, OUTPUT); + bitDelay(); + pinMode(m_pinClk, OUTPUT); + bitDelay(); + bitDelay(); + pinMode(m_pinClk, INPUT); + bitDelay(); + bitDelay(); + pinMode(m_pinDIO, INPUT); + bitDelay(); } bool TM1637Display::writeByte(uint8_t b) @@ -203,11 +240,12 @@ bool TM1637Display::writeByte(uint8_t b) // 8 Data Bits for(uint8_t i = 0; i < 8; i++) { + bitDelay(); // CLK low pinMode(m_pinClk, OUTPUT); bitDelay(); - // Set data bit + // Set data bit if (data & 0x01) pinMode(m_pinDIO, INPUT); else @@ -215,43 +253,94 @@ bool TM1637Display::writeByte(uint8_t b) bitDelay(); - // CLK high + // CLK high pinMode(m_pinClk, INPUT); bitDelay(); data = data >> 1; } - // Wait for acknowledge + // Wait for acknowledge (Cycle 9) // CLK to zero pinMode(m_pinClk, OUTPUT); + bitDelay(); pinMode(m_pinDIO, INPUT); bitDelay(); // CLK to high pinMode(m_pinClk, INPUT); - bitDelay(); uint8_t ack = digitalRead(m_pinDIO); - if (ack == 0) - pinMode(m_pinDIO, OUTPUT); - - bitDelay(); - pinMode(m_pinClk, OUTPUT); bitDelay(); - return ack; + return ack; // (Cycle 9 finished) } void TM1637Display::showDots(uint8_t dots, uint8_t* digits) { - for(int i = 0; i < 4; ++i) - { - digits[i] |= (dots & 0x80); - dots <<= 1; - } + for(int i = 0; i < m_noDigits; ++i) + { + digits[i] |= (dots & 0x80); + dots <<= 1; + } } uint8_t TM1637Display::encodeDigit(uint8_t digit) { - return digitToSegment[digit & 0x0f]; + return digitToSegment[digit & 0x0f]; } + +uint8_t TM1637Display::readByte() +{ + uint8_t b = 0; + pinMode(m_pinDIO, INPUT); + for(uint8_t i=0; i<8; i++) + { + pinMode(m_pinClk, OUTPUT); + bitDelay(); + bitDelay(); + pinMode(m_pinClk, INPUT); + bitDelay(); + b = (b << 1) | (digitalRead(m_pinDIO)==LOW?0:1); + bitDelay(); + } + + // Wait for acknowledge (Cycle 9) + // CLK to zero + pinMode(m_pinClk, OUTPUT); + bitDelay(); + bitDelay(); + + // CLK to high + pinMode(m_pinClk, INPUT); + uint8_t ack = digitalRead(m_pinDIO); + bitDelay(); + bitDelay(); + + if (ack != 0) return 0xFF; + return b; +} + +uint8_t key(uint8_t code) +{ + if (code == 0xff) return 0; + return (code >> 4) + 1; +} + +uint8_t TM1637Display::lastKeyCode() +{ + return key(m_KeyCode); +} + +uint8_t TM1637Display::getKeyCode() +{ + start(); + if (writeByte(TM1637_I2C_COMM4)) + { + stop(); + return 0;; + } + m_KeyCode = readByte(); + stop(); + return key(m_KeyCode); +} + diff --git a/TM1637Display.h b/TM1637Display.h index bc0dd13..7070938 100644 --- a/TM1637Display.h +++ b/TM1637Display.h @@ -1,4 +1,5 @@ // Author: avishorp@gmail.com +// Extended to 6 digits and key-scan: Guido Dampf // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public @@ -40,7 +41,7 @@ class TM1637Display { //! @param pinDIO - The number of the digital pin connected to the DIO pin of the module //! @param bitDelay - The delay, in microseconds, between bit transition on the serial //! bus connected to the display - TM1637Display(uint8_t pinClk, uint8_t pinDIO, unsigned int bitDelay = DEFAULT_BIT_DELAY); + TM1637Display(uint8_t pinClk, uint8_t pinDIO, unsigned int bitDelay = DEFAULT_BIT_DELAY, uint8_t noDigits = 4); //! Sets the brightness of the display. //! @@ -63,7 +64,7 @@ class TM1637Display { //! @param segments An array of size @ref length containing the raw segment values //! @param length The number of digits to be modified //! @param pos The position from which to start the modification (0 - leftmost, 3 - rightmost) - void setSegments(const uint8_t segments[], uint8_t length = 4, uint8_t pos = 0); + void setSegments(const uint8_t segments[], uint8_t length = 0, uint8_t pos = 0); //! Clear the display void clear(); @@ -79,7 +80,7 @@ class TM1637Display { //! fits to the number of digits requested (for example, if two digits are to be displayed, //! the number must be between 0 to 99) //! @param pos The position of the most significant digit (0 - leftmost, 3 - rightmost) - void showNumberDec(int num, bool leading_zero = false, uint8_t length = 4, uint8_t pos = 0); + void showNumberDec(long num, bool leading_zero = false, uint8_t length = 0, uint8_t pos = 0); //! Display a decimal number, with dot control //! @@ -104,7 +105,7 @@ class TM1637Display { //! fits to the number of digits requested (for example, if two digits are to be displayed, //! the number must be between 0 to 99) //! @param pos The position of the most significant digit (0 - leftmost, 3 - rightmost) - void showNumberDecEx(int num, uint8_t dots = 0, bool leading_zero = false, uint8_t length = 4, uint8_t pos = 0); + void showNumberDecEx(long num, uint8_t dots = 0, bool leading_zero = false, uint8_t length = 0, uint8_t pos = 0); //! Display a hexadecimal number, with dot control //! @@ -129,7 +130,7 @@ class TM1637Display { //! fits to the number of digits requested (for example, if two digits are to be displayed, //! the number must be between 0 to 99) //! @param pos The position of the most significant digit (0 - leftmost, 3 - rightmost) - void showNumberHexEx(uint16_t num, uint8_t dots = 0, bool leading_zero = false, uint8_t length = 4, uint8_t pos = 0); + void showNumberHexEx(uint16_t num, uint8_t dots = 0, bool leading_zero = false, uint8_t length = 0, uint8_t pos = 0); //! Translate a single digit into 7 segment code //! @@ -142,6 +143,25 @@ class TM1637Display { //! bit 6 - segment G; bit 7 - always zero) uint8_t encodeDigit(uint8_t digit); + //! Read a byte from register (usually containing the kay scanning code) + //! + //! The method sends the read key command and read the result into a variable + //! the result is tranfered into a number (0-16) and returned, + //! while 0 means - no key pressed + //! + //! @return A code representing the 16 buttons + uint8_t getKeyCode(); + + //! Read the last byte read from register (usually containing the kay scanning code) + //! + //! The method just re read the last result, which is always read again, + //! when display changed (setSegments called) or getKeyCode called + //! the result is tranfered into a number (0-16) and returned, + //! while 0 means - no key pressed + //! + //! @return A code representing the 16 buttons + uint8_t lastKeyCode(); + protected: void bitDelay(); @@ -151,16 +171,20 @@ class TM1637Display { bool writeByte(uint8_t b); + uint8_t readByte(); + void showDots(uint8_t dots, uint8_t* digits); - - void showNumberBaseEx(int8_t base, uint16_t num, uint8_t dots = 0, bool leading_zero = false, uint8_t length = 4, uint8_t pos = 0); + + void showNumberBaseEx(int8_t base, uint32_t num, uint8_t dots = 0, bool leading_zero = false, uint8_t length = 0, uint8_t pos = 0); private: - uint8_t m_pinClk; - uint8_t m_pinDIO; - uint8_t m_brightness; - unsigned int m_bitDelay; + uint8_t m_pinClk; + uint8_t m_pinDIO; + uint8_t m_brightness; + uint8_t m_noDigits; + unsigned int m_bitDelay; + uint8_t m_KeyCode; }; #endif // __TM1637DISPLAY__ diff --git a/examples/TM1637Test/TM1637Test.ino b/examples/TM1637Test/TM1637Test.ino index eb7c841..36f9ea8 100644 --- a/examples/TM1637Test/TM1637Test.ino +++ b/examples/TM1637Test/TM1637Test.ino @@ -1,21 +1,31 @@ #include -#include +#include "TM1637Display.h" // Module connection pins (Digital Pins) #define CLK 2 #define DIO 3 +#define NUMBEROFDIGITS 6 +// if you just have a booring 4 digit display w/o keypad, +// set NUMBEROFDIGITS 4 and uncomment the NOKEYPAD-define below + +// Uncomment the following, if you just want to test your Keypad +//#define JUSTTESTKEYPAD + +// Uncomment the following, if you don't have any Keypad +//#define NOKEYPAD // The amount of time (in milliseconds) between tests -#define TEST_DELAY 2000 +#define TEST_DELAY 500 const uint8_t SEG_DONE[] = { - SEG_B | SEG_C | SEG_D | SEG_E | SEG_G, // d - SEG_A | SEG_B | SEG_C | SEG_D | SEG_E | SEG_F, // O - SEG_C | SEG_E | SEG_G, // n - SEG_A | SEG_D | SEG_E | SEG_F | SEG_G // E - }; + SEG_B | SEG_C | SEG_D | SEG_E | SEG_G, // d + SEG_A | SEG_B | SEG_C | SEG_D | SEG_E | SEG_F, // O + SEG_C | SEG_E | SEG_G, // n + SEG_A | SEG_D | SEG_E | SEG_F | SEG_G, // E + 0,0 +}; -TM1637Display display(CLK, DIO); +TM1637Display display(CLK, DIO, 2, NUMBEROFDIGITS); void setup() { @@ -23,109 +33,240 @@ void setup() void loop() { - int k; - uint8_t data[] = { 0xff, 0xff, 0xff, 0xff }; - uint8_t blank[] = { 0x00, 0x00, 0x00, 0x00 }; - display.setBrightness(0x0f); + uint8_t blank[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; + uint8_t all[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; + display.setBrightness(0x03); - // All segments on - display.setSegments(data); - delay(TEST_DELAY); - - // Selectively set different digits + display.setSegments(blank); +#ifndef NOKEYPAD + while (!display.lastKeyCode()) + { + delay(100); + display.getKeyCode(); + } + display.showNumberDec(display.lastKeyCode(), false); +// display.showNumberHexEx(display.lastKeyCode(), false); + delay(500); + display.clear(); +#endif +#ifndef JUSTTESTKEYPAD + int k; + long i; + uint8_t data[6]; data[0] = display.encodeDigit(0); data[1] = display.encodeDigit(1); data[2] = display.encodeDigit(2); data[3] = display.encodeDigit(3); - display.setSegments(data); - delay(TEST_DELAY); - - /* - for(k = 3; k >= 0; k--) { - display.setSegments(data, 1, k); - delay(TEST_DELAY); - } - */ + data[4] = display.encodeDigit(4); + data[5] = display.encodeDigit(5); - display.clear(); - display.setSegments(data+2, 2, 2); - delay(TEST_DELAY); - - display.clear(); - display.setSegments(data+2, 2, 1); - delay(TEST_DELAY); - - display.clear(); - display.setSegments(data+1, 3, 1); - delay(TEST_DELAY); +#ifndef NOKEYPAD + if (display.lastKeyCode()==1) +#endif + { + + // All segments on + display.setSegments(all); + delay(TEST_DELAY); + display.clear(); + } + + // Selectively set different digits +#ifndef NOKEYPAD + if (display.lastKeyCode()==2) +#endif + { + display.setSegments(data); + delay(TEST_DELAY); + display.clear(); + } - // Show decimal numbers with/without leading zeros - display.showNumberDec(0, false); // Expect: ___0 - delay(TEST_DELAY); - display.showNumberDec(0, true); // Expect: 0000 - delay(TEST_DELAY); - display.showNumberDec(1, false); // Expect: ___1 - delay(TEST_DELAY); - display.showNumberDec(1, true); // Expect: 0001 - delay(TEST_DELAY); - display.showNumberDec(301, false); // Expect: _301 - delay(TEST_DELAY); - display.showNumberDec(301, true); // Expect: 0301 - delay(TEST_DELAY); - display.clear(); - display.showNumberDec(14, false, 2, 1); // Expect: _14_ - delay(TEST_DELAY); - display.clear(); - display.showNumberDec(4, true, 2, 2); // Expect: 04__ - delay(TEST_DELAY); - display.showNumberDec(-1, false); // Expect: __-1 - delay(TEST_DELAY); - display.showNumberDec(-12); // Expect: _-12 - delay(TEST_DELAY); - display.showNumberDec(-999); // Expect: -999 - delay(TEST_DELAY); - display.clear(); - display.showNumberDec(-5, false, 3, 0); // Expect: _-5_ - delay(TEST_DELAY); - display.showNumberHexEx(0xf1af); // Expect: f1Af - delay(TEST_DELAY); - display.showNumberHexEx(0x2c); // Expect: __2C - delay(TEST_DELAY); - display.showNumberHexEx(0xd1, 0, true); // Expect: 00d1 - delay(TEST_DELAY); - display.clear(); - display.showNumberHexEx(0xd1, 0, true, 2); // Expect: d1__ - delay(TEST_DELAY); +#ifndef NOKEYPAD + if (display.lastKeyCode()==3) +#endif + { + for(k = NUMBEROFDIGITS-1; k >= 0; k--) { + display.setSegments(data, 1, k); + delay(TEST_DELAY); + } + display.clear(); + } - // Run through all the dots - for(k=0; k <= 4; k++) { - display.showNumberDecEx(0, (0x80 >> k), true); - delay(TEST_DELAY); - } - - // Brightness Test - for(k = 0; k < 4; k++) - data[k] = 0xff; - for(k = 0; k < 7; k++) { - display.setBrightness(k); - display.setSegments(data); +#ifndef NOKEYPAD + if (display.lastKeyCode()==4) +#endif + { + display.setSegments(data+2, 2, 2); delay(TEST_DELAY); + display.clear(); } - // On/Off test - for(k = 0; k < 4; k++) { - display.setBrightness(7, false); // Turn off - display.setSegments(data); +#ifndef NOKEYPAD + if (display.lastKeyCode()==5) +#endif + { + display.setSegments(data+2, 2, 1); delay(TEST_DELAY); - display.setBrightness(7, true); // Turn on - display.setSegments(data); - delay(TEST_DELAY); + display.clear(); + } + +#ifndef NOKEYPAD + if (display.lastKeyCode()==6) +#endif + { + display.setSegments(data+1, 3, 1); + delay(TEST_DELAY); + display.clear(); } - - // Done! - display.setSegments(SEG_DONE); + // Show decimal numbers with/without leading zeros +#ifndef NOKEYPAD + if (display.lastKeyCode()==7) +#endif + { + display.showNumberDec(0, false); // Expect: ___0 + delay(TEST_DELAY); + display.showNumberDec(0, true); // Expect: 0000 + delay(TEST_DELAY); + display.clear(); + } +#ifndef NOKEYPAD + if (display.lastKeyCode()==8) +#endif + { + display.showNumberDec(1, false); // Expect: ___1 + delay(TEST_DELAY); + display.showNumberDec(1, true); // Expect: 0001 + delay(TEST_DELAY); + display.clear(); + } +#ifndef NOKEYPAD + if (display.lastKeyCode()==9) +#endif + { + display.showNumberDec(301, false); // Expect: _301 + delay(TEST_DELAY); + display.showNumberDec(301, true); // Expect: 0301 + delay(TEST_DELAY); + display.clear(); + } +#ifndef NOKEYPAD + if (display.lastKeyCode()==10) +#endif + { + display.showNumberDec(14, false, 2, 1); // Expect: _14_ + delay(TEST_DELAY); + display.clear(); + display.showNumberDec(4, true, 2, 2); // Expect: 04__ + delay(TEST_DELAY); + display.clear(); + } +#ifndef NOKEYPAD + if (display.lastKeyCode()==11) +#endif + { + display.showNumberDec(-1, false); // Expect: __-1 + delay(TEST_DELAY); + display.showNumberDec(-12); // Expect: _-12 + delay(TEST_DELAY); + display.showNumberDec(-999); // Expect: -999 + delay(TEST_DELAY); + display.clear(); + display.showNumberDec(-5, false, 3, 0); // Expect: _-5_ + delay(TEST_DELAY); + display.clear(); + } +#ifndef NOKEYPAD + if (display.lastKeyCode()==12) +#endif + { + display.showNumberHexEx(0xf1af); // Expect: f1Af + delay(TEST_DELAY); + display.showNumberHexEx(0x2c); // Expect: __2C + delay(TEST_DELAY); + display.showNumberHexEx(0xd1, 0, true); // Expect: 00d1 + delay(TEST_DELAY); + display.clear(); + display.showNumberHexEx(0xd1, 0, true, 2); // Expect: d1__ + delay(TEST_DELAY); + display.clear(); + } + +#ifndef NOKEYPAD + if (display.lastKeyCode()==13) +#endif + { + // Run through all the dots + for(k=0; k <= NUMBEROFDIGITS; k++) { + display.showNumberDecEx(0, (0x80 >> k), true); + delay(TEST_DELAY); + } + display.clear(); + } - while(1); +#ifndef NOKEYPAD + if (display.lastKeyCode()==14) +#endif + { + // Brightness Test +// for(k = 0; k < 8; k++) { + for(k = 0; k < 4; k++) { // low power led just need up to 3 + display.setBrightness(k); + display.setSegments(all); + delay(TEST_DELAY); + } + display.clear(); + } + +#ifndef NOKEYPAD + if (display.lastKeyCode()==15) +#endif + { + // On/Off test + for(k = 0; k < NUMBEROFDIGITS; k++) { +// display.setBrightness(7, false); + display.setBrightness(3, false); // Turn off + display.setSegments(all); + delay(TEST_DELAY); +// display.setBrightness(7, true); + display.setBrightness(3, true); // Turn on + display.setSegments(all); + delay(TEST_DELAY); + } + display.clear(); + } + +#ifndef NOKEYPAD + if (display.lastKeyCode()==16) +#endif + { + long startno=999999; + long stopno=-100000; + int k = 6; + + while ((k--) - NUMBEROFDIGITS > 0) + { + startno /= 10; + stopno /= 10; + } + + for(i=startno;(i>stopno) +#ifndef NOKEYPAD + && (i > startno-1000 || display.lastKeyCode()==0) +#endif + ;i--) { + display.showNumberDec(i, false); + delay(8); // adjusted to around 1/100 sec cycle-time + } + display.clear(); + + // Done! + display.setSegments(SEG_DONE); + delay(2000); + display.clear(); + } + + delay(100); +#endif } diff --git a/keywords.txt b/keywords.txt index 8a43483..68af4db 100644 --- a/keywords.txt +++ b/keywords.txt @@ -15,6 +15,8 @@ showNumberDec KEYWORD2 showNumberDecEx KEYWORD2 showNumberHexEx KEYWORD2 encodeDigit KEYWORD2 +getKeyCode KEYWORD2 +lastKeyCode KEYWORD2 ####################################### # Constants (LITERAL1) diff --git a/library.json b/library.json index 12c0417..4f6ce0a 100644 --- a/library.json +++ b/library.json @@ -4,11 +4,11 @@ "description": "Arduino library for TM1637 (LED Driver)", "repository": { "type": "git", - "url": "https://github.com/avishorp/TM1637.git" + "url": "https://github.com/gdampf/TM1637.git" }, "frameworks": "arduino", "platforms": [ "atmelavr", "espressif" ] -} \ No newline at end of file +} diff --git a/library.properties b/library.properties index f542e39..6214395 100644 --- a/library.properties +++ b/library.properties @@ -1,11 +1,11 @@ name=TM1637 version=1.2.0 -author=Avishay Orpaz -maintainer=Avishay Orpaz -sentence=Driver for 4 digit 7-segment display modules, based on the TM1637 chip. -paragraph=These chips can be found in cheap display modules. They communicate with the processor in I2C-like protocol. The implementation is pure software emulation and doesn't make use of any special hardware (other than GPIO pins). It is assumed that pull-up resistors are present (usually integrated in the display module). +author=Guido Dampf +maintainer=Guido Dampf +sentence=Driver for 6 digit 7-segment display incl. Keypad, based on the TM1637 chip. +paragraph=These chips can be found in cheap display modules as well as DIP-Chips. They communicate with the processor in I2C-like protocol. The implementation is pure software emulation and doesn't make use of any special hardware (other than GPIO pins). It is assumed that pull-up resistors are present (usually integrated in the display module). category=Display -url=https://github.com/avishorp/TM1637 +url=https://github.com/gdampf/TM1637 architectures=* includes=TM1637.h diff --git a/release_notes.md b/release_notes.md index c10f725..6785822 100644 --- a/release_notes.md +++ b/release_notes.md @@ -1,3 +1,8 @@ +- V1.3.0 + * Add support for 6 digits + * Add support for keypad scan + * Taken over to own repository + - V1.2.0 * Add support for negative numbers * Add support for hexadeciaml number