diff --git a/extra/LICENSE.md b/LICENSE.md similarity index 100% rename from extra/LICENSE.md rename to LICENSE.md diff --git a/README.md b/README.md index b8b19a3..e3a7f97 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,6 @@ +[![Website](https://img.shields.io/badge/Website-Link-blue.svg)](https://gavinlyonsrepo.github.io/) [![Rss](https://img.shields.io/badge/Subscribe-RSS-yellow.svg)](https://gavinlyonsrepo.github.io//feed.xml) [![Donate](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://www.paypal.com/paypalme/whitelight976) + + ![ module pics ](https://github.com/gavinlyonsrepo/TM1638plus/blob/master/extra/images/tm16383.jpg) Table of contents @@ -10,7 +13,6 @@ Table of contents * [Model Two](#model-two) * [Model Three](#model-three) * [Notes](#notes) - * [Memory](#memory) * [Ports](#ports) Overview @@ -24,7 +26,6 @@ This library supports 3 different models, pictured above from left to right. 2. Model 2, The (QYF 16 KEY) variant which has 16 pushbuttons. 3. Model 3, The (LKM1638) variant which has 8 bi-colour LED's and 8 Push buttons. - * Main Author: Gavin Lyons. * Tested on Development platforms: @@ -37,10 +38,6 @@ This library supports 3 different models, pictured above from left to right. 6. Teensy 4.0. (may not work at highest frequency see notes section) * History: see CHANGELOG.md in extra folder -* Contributors: [gabormay](https://github.com/gabormay) [centic9](https://github.com/centic9) [wunderbaum](https://github.com/wunderbaum) - -[![Donate](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://www.paypal.com/paypalme/whitelight976) - Installation ------------------------------ @@ -106,8 +103,9 @@ For more information see the commented headers in header file. 1. Print an ASCII character. 2. Print an ASCII character with a dot/decimal point. 3. Print a Hexadecimal digit(0-15). -4. Print a long integer number with or without leading zeros. -5. Print two integer numbers (0-9999) to each nibble with or without leading zeros. +4. Print a long integer number with or without leading zeros, and right and left aligned text. +5. Print two integer numbers (0-9999) to each nibble with or without leading zeros, +and right and left aligned text. 6. Print a text string(dots are replaced and dot is turned on preceding digit), "abc.def" becomes "abcdef" with c decimal point segment switched on. 7. Read buttons status. User may have to debounce buttons depending on application. @@ -142,10 +140,11 @@ The commented functions can be found in library header file TM1638plus_Model2.h. The library support Strings,decimal ,Hex ,raw ASCII data, setting individual segments, and the decimal point. For more detailed information on functions see commented headers in header file(.h). -1. Print a Hexadecimal number with or without leading zeros -2. Print a decimal number with or without leading zeros +1. Print a Hexadecimal number with or without leading zeros, and right and left aligned text. +2. Print a decimal number with or without leading zeros, and right and left aligned text. 3. Manually set segments to create custom patterns. -4. Print two 4 digit decimal number(0-9999) to each nibble with or without leading zeros. +4. Print two 4 digit decimal number(0-9999) to each nibble with or without leading zeros, +and right and left aligned text. 5. Print a text string, dot function supported. 6. Read buttons status. User may want to debounce buttons depending on application. See TM1638plus_ADC_TEST_Model2.ino for debounce button example. @@ -199,7 +198,7 @@ Notes 3. Driving multiple displays. 4. Detecting multiple buttons pressed together. -*Note A* : Swapped display Issue: Model 2 only +*Note 1* : Swapped display Issue: Model 2 only For Some users using this library the nibbles in information display byte where swapped around. This is because there are different versions of modules on market with different wiring. See issue #3 on github called Swapped display :: "12345678" becomes "56781234". @@ -211,7 +210,7 @@ Object, set the fourth parameter "swap_nibbles" to True, The default is false. | QYF-TM1638 | default operation | false | | QYF-TM1638 -Ver 1.0 | Swapped display Fix | true | -*Note B* : High frequency micro-controllers. +*Note 2* : High frequency micro-controllers. This library uses a software SPI-like protocol and may not work fully on micro-controllers running at a very high frequency, without some adjustments to timing. @@ -236,12 +235,12 @@ The Teensy results have been sent in by email, I don't have these MCU's them at | Teensy 4.0| 150Mhz | Working model 1, no Data rest of models | | Teensy 4.0| 396Mhz | Not working on m1 pre v1.6, no data after, no Data rest of models | -*Note C* : Driving multiple displays. +*Note 3* : Driving multiple displays. It is possible to drive multiple modules. Share the DIO and CLK lines and use a unique STB line for each device. see issue number 10 at github for example code. -*Note D* : Detecting multiple buttons pressed together. +*Note 4* : Detecting multiple buttons pressed together. Model 1 and Model 3 CAN detect multiple buttons pressed. @@ -256,21 +255,6 @@ Pressing Certain combinations of buttons will cause the data on Seven Segments change. So the simultaneous use of multiple key presses and the seven segments display is problematic. See issue 12 on github for more details. -Memory -------------------------------- - -Version 1.4. - -1. Model 1 memory usage NANO, basic hello world sketch. - -Sketch uses 1488 bytes (4%) of program storage space. -Global variables use 22 bytes (1%) of dynamic memory. - -2. Model 2 memory usage NANO, basic hello world sketch. - -Sketch uses 1536 bytes (5%) of program storage space. -Global variables use 23 bytes (1%) of dynamic memory. - Ports ------------------- diff --git a/examples/TM1638plus_TEST_Model1/TM1638plus_TEST_Model1.ino b/examples/TM1638plus_TEST_Model1/TM1638plus_TEST_Model1.ino index 8a82131..f568dd6 100644 --- a/examples/TM1638plus_TEST_Model1/TM1638plus_TEST_Model1.ino +++ b/examples/TM1638plus_TEST_Model1/TM1638plus_TEST_Model1.ino @@ -2,7 +2,7 @@ Project Name: TM1638 File: TM1638plus_TEST_Model1.ino Description: demo file library for TM1638 module(LED & KEY). Model 1 - Carries out series of tests demonstrating arduino library TM1638plus. + Carries out series of tests to demo arduino library TM1638plus. TESTS: TEST 0 Reset @@ -42,8 +42,7 @@ TM1638plus tm(STROBE_TM, CLOCK_TM , DIO_TM, high_freq); // Some vars and defines for the tests. #define myTestDelay 5000 #define myTestDelay1 1000 -uint8_t testcount = 0; - +#define myTestDelay3 3000 void setup() { @@ -57,24 +56,20 @@ void setup() void loop() { - switch (testcount) - { - case 1: Test1(); break; // Brightness - case 2: Test2(); break; // ASCII display - case 3: Test3(); break; // Set a single segment - case 4: Test4(); break; // Hex digits - case 5: Test5(); break; // Text String with Decimal point - case 6: Test6(); break; // TEXT + ASCII combo - case 7: Test7(); break; // Integer Decimal number - case 8: Test8(); break; // Text String + Float hack - case 9: Test9(); break; // Text String + decimal number - case 10: Test10(); break; // Multiple Decimal points - case 11: Test11(); break; // Display Overflow - case 12: Test12(); break; // Scrolling text - case 13: Test13(); break; // setLED and setLEDs - case 14: Test14(); break; // Buttons + LEDS - } - testcount++; + Test1(); // Brightness + Test2(); // ASCII display + Test3(); // Set a single segment in each digit + Test4(); // Hex digits + Test5(); // Text String with Decimal point + Test6(); // TEXT + ASCII combo + Test7(); // Integer Decimal number + Test8(); // Text String + Float hack + Test9(); // Text String + decimal number + Test10(); // Multiple Decimal points + Test11(); // Display Overflow + Test12(); // Scrolling text + Test13(); // setLED and setLEDs + Test14(); // Buttons + LEDS } void Test0() @@ -105,38 +100,48 @@ void Test2() { tm.displayASCII(1, '3'); tm.displayASCII(2, '4'); tm.displayASCII(3, '1'); - delay(myTestDelay); + delay(myTestDelay3); tm.reset(); } void Test3() { - //TEST 3 single segment (pos, (dp)gfedcba) - //In this case segment g (middle dash) of digit position 7 - tm.display7Seg(7, 0b01000000); // Displays " -" - delay(myTestDelay); + //TEST 3 single segment (digit position, (dp)gfedcba) + // (dp)gfedcba = seven segments positions + uint8_t pos = 0; + for (pos = 0 ; pos<8 ; pos++) + { + tm.display7Seg(pos, 1<<7-pos); // Displays a single seg in (dp)gfedcba) in each pos 0-7 + delay(myTestDelay1); + } } void Test4() { // Test 4 Hex digits. - tm.displayHex(0, 1); - tm.displayHex(1, 2); - tm.displayHex(2, 3); - tm.displayHex(3, 4); - tm.displayHex(4, 5); - tm.displayHex(5, 6); - tm.displayHex(6, 7); - tm.displayHex(7, 8); - delay(myTestDelay); // display 12345678 + tm.displayHex(0, 0); + tm.displayHex(1, 1); + tm.displayHex(2, 2); + tm.displayHex(3, 3); + tm.displayHex(4, 4); + tm.displayHex(5, 5); + tm.displayHex(6, 6); + tm.displayHex(7, 7); + delay(myTestDelay3); // display 01234567 tm.displayHex(0, 8); tm.displayHex(1, 9); - tm.displayHex(2, 10); - tm.displayHex(3, 11); - tm.displayHex(4, 12); - tm.displayHex(5, 13); - tm.displayHex(6, 14); - tm.displayHex(7, 15); - delay(myTestDelay); // display 89ABCDEF + tm.displayHex(2, 0x0A); + tm.displayHex(3, 0x0B); + tm.displayHex(4, 0x0C); + tm.displayHex(5, 0x0D); + tm.displayHex(6, 0x0E); + tm.displayHex(7, 0x0F); + delay(myTestDelay3); // display 89ABCDEF + tm.reset(); + + tm.displayHex(1, 0xFFFE); + tm.displayHex(7, 0x10); + delay(myTestDelay3); // display " E 0" + } void Test5() { @@ -160,18 +165,33 @@ void Test6() { } void Test7() { - // TEST 7a Integer - tm.displayIntNum(45, false); // "45 " + // TEST 7a Integer left aligned , NO leading zeros + tm.displayIntNum(45, false, TMAlignTextLeft); // "45 " delay(myTestDelay); - // TEST 7b Integer - tm.displayIntNum(99991, true); // "00099991" + // TEST 7b Integer left aligned , leading zeros + tm.displayIntNum(99991, true, TMAlignTextLeft); // "00099991" delay(myTestDelay); tm.reset(); - // TEST 7b tm.DisplayDecNumNIbble - tm.DisplayDecNumNibble(1234, 5678, false); // "12345678" + // TEST 7c Integer right aligned , NO leading zeros + tm.displayIntNum(35, false, TMAlignTextRight); // " 35" delay(myTestDelay); - tm.DisplayDecNumNibble(123, 662, true); // "01230662" + // TEST 7d Integer right aligned , leading zeros + tm.displayIntNum(9983551, true, TMAlignTextRight); // "09983551" delay(myTestDelay); + + // TEST 7e tm.DisplayDecNumNIbble left aligned + tm.DisplayDecNumNibble(134, 70, false, TMAlignTextLeft); // "134 " "70" , left aligned, NO leading zeros + delay(myTestDelay); + tm.DisplayDecNumNibble(23, 662, true, TMAlignTextLeft); // "0023" "0662" , left aligned , leading zeros + delay(myTestDelay); + tm.reset(); + + // TEST 7f tm.DisplayDecNumNIbble right aligned + tm.DisplayDecNumNibble(43, 991, false, TMAlignTextRight); // " 43" " 991" , right aligned, NO leading zeros + delay(myTestDelay); + tm.DisplayDecNumNibble(53, 8, true, TMAlignTextRight); // "0053" "0008" , right aligned , leading zeros + delay(myTestDelay); + } void Test8() { @@ -180,7 +200,7 @@ void Test8() { uint16_t data = 234; sprintf(workStr, "ADC=.%04d", data); // "ADC=.0234" tm.displayText(workStr); - delay(myTestDelay); + delay(myTestDelay3); } void Test9() { @@ -198,7 +218,7 @@ void Test9() { sprintf(workStr, "ADC=.%d%d.%d%d", digit1, digit2, digit3, digit4); tm.displayText(workStr); //12.45.VOLT - delay(myTestDelay); + delay(myTestDelay3); tm.reset(); } @@ -215,7 +235,7 @@ void Test11() { //TEST11 user overflow tm.displayText("1234567890abc"); //should display just 12345678 - delay(myTestDelay); + delay(myTestDelay3); tm.reset(); } @@ -262,13 +282,13 @@ void Test13() // NOTE passed L8-L1 and on display L8 is on right hand side. i.e. 0x01 turns on L1. LXXX XXXX // For model 1 just use upper byte , lower byte is is used by model3 for bi-color leds leave at 0x00 for model 1. tm.setLEDs(0xFF00); // all LEDs on - delay(3000); + delay(myTestDelay3); tm.setLEDs(0x0100); // Displays as LXXX XXXX (L1-L8) , NOTE on display L8 is on right hand side. - delay(3000); + delay(myTestDelay3); tm.setLEDs(0xF000); // Displays as XXXX LLLL (L1-L8) , NOTE on display L8 is on right hand side. - delay(3000); + delay(myTestDelay3); tm.setLEDs(0x0000); // all off - delay(3000); + delay(myTestDelay3); } @@ -276,6 +296,7 @@ void Test14() { //Test 14 buttons and LED test, press switch number S-X to turn on LED-X, where x is 1-8. //The HEx value of switch is also sent to Serial port. tm.displayText("buttons "); + delay(myTestDelay3); while (1) // Loop here forever { uint8_t buttons = tm.readButtons(); @@ -292,7 +313,7 @@ void Test14() { */ Serial.println(buttons, HEX); doLEDs(buttons); - tm.displayIntNum(buttons, true); + tm.displayIntNum(buttons, true, TMAlignTextLeft); delay(250); } } diff --git a/examples/TM1638plus_TEST_Model2/TM1638plus_TEST_Model2.ino b/examples/TM1638plus_TEST_Model2/TM1638plus_TEST_Model2.ino index 68d4833..bf6fe27 100644 --- a/examples/TM1638plus_TEST_Model2/TM1638plus_TEST_Model2.ino +++ b/examples/TM1638plus_TEST_Model2/TM1638plus_TEST_Model2.ino @@ -72,35 +72,63 @@ void Serialinit() { Serial.begin(9600); delay( myTestDelay); - Serial.println("-- TM1638 M2 test : Comms UP --"); + Serial.println("-- TM1638 Model2 test : Comms UP --"); } void Test1(void) { // Test 1 decimal numbers - tm.DisplayDecNum(250, 1 << 2, true); // 000002.50 + // 1a-1e test tm.DisplayDecNum method + // 1a Left aligned leading zeros + tm.DisplayDecNum(250, 1 << 2, true, TMAlignTextLeft); // 000002.50 delay(myTestDelay); - tm.DisplayDecNum(99991111, 1 << 4, true); // 9999.1111 + // 1b left aligned NO leading zeros + tm.DisplayDecNum(991111, 1 << 4, false, TMAlignTextLeft); // "9911.11 " delay(myTestDelay); - tm.DisplayDecNum(2888, 0 , true); // 00002888 + + // 1c right aligned leading zeros + tm.DisplayDecNum(2813, 0 , true, TMAlignTextRight); // 00002813 + delay(myTestDelay); + + // 1d right aligned NO leading zeros + tm.DisplayDecNum(331285, 1 << 5 ,false, TMAlignTextRight); // " 3.31285" + delay(myTestDelay); + + // 1e negative number + tm.DisplayDecNum(-33, 0 , false, TMAlignTextRight); // " -33" delay(myTestDelay); - tm.DisplayDecNum(331285, 1 <<4 ,false); // "3312.85 " + + //1f-1i test tm.DisplayDecNumNibble + // decimal numbers with the DisplayDecNumNibble function divides display into two nibbles. + + // 1f Left aligned leading zeros, + tm.DisplayDecNumNibble(21 , 178, 0, true, TMAlignTextLeft); // "00210178" + delay(myTestDelay); + // 1g Left aligned, NO leading zeros + tm.DisplayDecNumNibble(21 , 78, 1<<3 , false, TMAlignTextLeft); // "21 7.8 " delay(myTestDelay); - tm.DisplayDecNum(-33, 0 , false); // "-33 " + // 1h right aligned leading zeros + tm.DisplayDecNumNibble(977 , 34, 1<<4 , true, TMAlignTextRight); // "0977.0034" delay(myTestDelay); - // Test 1b decimal numbers with the DisplayDecNumNibble function divides display into two nibbles. - tm.DisplayDecNumNibble(2134 , 78, 1<<4 , true); // "2134.0078" + // 1i right aligned, NO leading zeros + tm.DisplayDecNumNibble(14 , 729, 1<<5 , false, TMAlignTextRight); // " 1.4 729" delay(myTestDelay); } void Test2(void) { // Test 2 Hexadecimal number - tm.DisplayHexNum(0x0000, 0x456E, 0x00, true); // 0000456E + // 2a leading zeros left alignment + tm.DisplayHexNum(0xF, 0x456E, 0x00, true, TMAlignTextLeft); // 000F456E delay(myTestDelay); - tm.DisplayHexNum(0xABCD, 0xEF23, 0x00, true); // ABCDEF23 + // 2b NO leading zeros left alignment + tm.DisplayHexNum(0xCD, 0xF23, 0x00, false, TMAlignTextLeft); // "CD F23 " delay(myTestDelay); - tm.DisplayHexNum(0x0000, 0x00FF, 1 << 4); // 0000.00FF + // 2c leading zeros right alignment + tm.DisplayHexNum(0x45, 0xFF, 1 << 4, true, TMAlignTextRight); // 0045.00FF + delay(myTestDelay); + // 2d NO leading zeros right alignment + tm.DisplayHexNum(0xFAE, 0xFF, 0x00, false, TMAlignTextRight); // " FAE FF" delay(myTestDelay); } @@ -186,7 +214,7 @@ void Test6(void) tm.reset(); } -// Just one possible method to scroll text there are many others. +// Just one possible method to scroll text. void Test7(void) { char textScroll[17] = " Hello world 123"; @@ -221,7 +249,7 @@ void Test8(void) // returns 0-16 , 0 for nothing pressed. // NOTE: pressing S16 will move to test 9 buttons = tm.ReadKey16(); - tm.DisplayDecNum(buttons, 0 ,false); + tm.DisplayDecNum(buttons, 0 ,false, TMAlignTextRight); Serial.println(buttons); delay( myTestDelay2); if (buttons == 16) @@ -250,6 +278,7 @@ void Test9(void) buttons = tm.ReadKey16Two(); Serial.println(buttons, HEX); tm.DisplayStr("buttons2", 0); - delay( myTestDelay2); + //tm.DisplayHexNum(0x0, buttons, 0 ,true, TMAlignTextRight); + delay(myTestDelay2); } } diff --git a/examples/TM1638plus_TEST_Model3/TM1638plus_TEST_Model3.ino b/examples/TM1638plus_TEST_Model3/TM1638plus_TEST_Model3.ino index aee3eef..dd0a3f2 100644 --- a/examples/TM1638plus_TEST_Model3/TM1638plus_TEST_Model3.ino +++ b/examples/TM1638plus_TEST_Model3/TM1638plus_TEST_Model3.ino @@ -44,6 +44,7 @@ TM1638plus tm(STROBE_TM, CLOCK_TM , DIO_TM, high_freq); // Some vars and defines for the tests. #define myTestDelay 5000 #define myTestDelay1 1000 +#define myTestDelay3 3000 uint8_t testcount = 1; @@ -107,38 +108,48 @@ void Test2() { tm.displayASCII(1, '3'); tm.displayASCII(2, '4'); tm.displayASCII(3, '2'); - delay(myTestDelay); + delay(myTestDelay3); tm.reset(); } void Test3() { - //TEST 3 single segment (pos, (dp)gfedcba) - //In this case segment g (middle dash) of digit position 7 - tm.display7Seg(7, 0b01000000); - delay(myTestDelay); + //TEST 3 single segment (digit position, (dp)gfedcba) + // (dp)gfedcba = seven segments positions + uint8_t pos = 0; + for (pos = 0 ; pos<8 ; pos++) + { + tm.display7Seg(pos, 1<<7-pos); // Displays a single seg in (dp)gfedcba) in each pos 0-7 + delay(myTestDelay1); + } } void Test4() { // Test 4 Hex digits. - tm.displayHex(0, 1); - tm.displayHex(1, 2); - tm.displayHex(2, 3); - tm.displayHex(3, 4); - tm.displayHex(4, 5); - tm.displayHex(5, 6); - tm.displayHex(6, 7); - tm.displayHex(7, 8); - delay(myTestDelay); + tm.displayHex(0, 0); + tm.displayHex(1, 1); + tm.displayHex(2, 2); + tm.displayHex(3, 3); + tm.displayHex(4, 4); + tm.displayHex(5, 5); + tm.displayHex(6, 6); + tm.displayHex(7, 7); + delay(myTestDelay3); tm.displayHex(0, 8); tm.displayHex(1, 9); - tm.displayHex(2, 10); - tm.displayHex(3, 11); - tm.displayHex(4, 12); - tm.displayHex(5, 13); - tm.displayHex(6, 14); - tm.displayHex(7, 15); - delay(myTestDelay); + tm.displayHex(2, 0x0A); + tm.displayHex(3, 0x0B); + tm.displayHex(4, 0x0C); + tm.displayHex(5, 0x0D); + tm.displayHex(6, 0x0E); + tm.displayHex(7, 0x0F); + delay(myTestDelay3); + + tm.reset(); + + tm.displayHex(1, 0xFFFE); + tm.displayHex(7, 0x10); + delay(myTestDelay3); // display " E 0" } void Test5() { @@ -157,23 +168,38 @@ void Test6() { tm.displayASCII(5, '5'); tm.displayASCII(6, '4'); tm.displayASCII(7, '1'); - delay(myTestDelay); + delay(myTestDelay3); tm.reset(); } void Test7() { - // TEST 7a Integer - tm.displayIntNum(72, false); // "72 " + // TEST 7a Integer left aligned , NO leading zeros + tm.displayIntNum(45, false, TMAlignTextLeft); // "45 " delay(myTestDelay); - // TEST 7b Integer - tm.displayIntNum(92345, true); // "00092345" + // TEST 7b Integer left aligned , leading zeros + tm.displayIntNum(99991, true, TMAlignTextLeft); // "00099991" delay(myTestDelay); tm.reset(); - // TEST 7b tm.DisplayDecNumNIbble - tm.DisplayDecNumNibble(1488, 5678, false); // "14885678" + // TEST 7c Integer right aligned , NO leading zeros + tm.displayIntNum(35, false, TMAlignTextRight); // " 35" delay(myTestDelay); - tm.DisplayDecNumNibble(123, 998, true); // "01230998" + // TEST 7d Integer right aligned , leading zeros + tm.displayIntNum(9983551, true, TMAlignTextRight); // "09983551" delay(myTestDelay); + + // TEST 7e tm.DisplayDecNumNIbble left aligned + tm.DisplayDecNumNibble(134, 70, false, TMAlignTextLeft); // "134 " "70" , left aligned, NO leading zeros + delay(myTestDelay); + tm.DisplayDecNumNibble(23, 662, true, TMAlignTextLeft); // "0023" "0662" , left aligned , leading zeros + delay(myTestDelay); + tm.reset(); + + // TEST 7f tm.DisplayDecNumNIbble right aligned + tm.DisplayDecNumNibble(43, 991, false, TMAlignTextRight); // " 43" " 991" , right aligned, NO leading zeros + delay(myTestDelay); + tm.DisplayDecNumNibble(53, 8, true, TMAlignTextRight); // "0053" "0008" , right aligned , leading zeros + delay(myTestDelay3); + } void Test8() { @@ -182,7 +208,7 @@ void Test8() { uint16_t data = 294; sprintf(workStr, "ADC=.%04d", data); // "ADC=.0294" tm.displayText(workStr); - delay(myTestDelay); + delay(myTestDelay3); } void Test9() { @@ -200,7 +226,7 @@ void Test9() { sprintf(workStr, "ADC=.%d%d.%d%d", digit1, digit2, digit3, digit4); tm.displayText(workStr); //12.45.VOLT - delay(myTestDelay); + delay(myTestDelay3); tm.reset(); } @@ -208,16 +234,16 @@ void Test10() { //TEST 10 Multiple dots test tm.displayText("Hello..."); - delay(myTestDelay); + delay(myTestDelay3); tm.displayText("...---..."); //SOS in morse - delay(myTestDelay); + delay(myTestDelay3); } void Test11() { //TEST11 user overflow tm.displayText("1234567890abc"); //should display just 12345678 - delay(myTestDelay); + delay(myTestDelay3); tm.reset(); } @@ -278,18 +304,18 @@ void Test13() // Shows on display as LED1-LED8 turns on RRRXXGGG as LED 8 is on right hand side. tm.setLEDs(0xE007); //L1-L8 turns on RRRXXGGG on display - delay(3000); + delay(myTestDelay3); tm.setLEDs(0xF00F); // L1-L8 turns on RRRRGGGG on display - delay(3000); + delay(myTestDelay3); tm.setLEDs(0xFE01); // L1-L8 turns on RGGGGGGG on display - delay(3000); + delay(myTestDelay3); tm.setLEDs(0x00FF); //all red RRRRRRR - delay(3000); + delay(myTestDelay3); tm.setLEDs(0xFF00); //all green GGGGGGG - delay(3000); + delay(myTestDelay3); tm.setLEDs(0x0000); //all off - delay(3000); + delay(myTestDelay3); } @@ -326,5 +352,5 @@ void Serialinit() { Serial.begin(9600); delay(100); - Serial.println("--Comms UP--TM1638plus_TEST_Model1.ino--"); + Serial.println("--Comms UP--TM1638plus_TEST_Model3.ino--"); } diff --git a/extra/CHANGELOG.md b/extra/CHANGELOG.md index 7ac97da..b8479e3 100755 --- a/extra/CHANGELOG.md +++ b/extra/CHANGELOG.md @@ -52,3 +52,11 @@ * Version 1.8.0 November 2021 * Minor update * Some users (two) have reported the high frequency shiftIn function does not work fully with some micro-controller boards at high frequency(ESP32 240Mhz) and the fix is minor adjustment to sequence in said function. Never saw the issue in my testing. The change makes the function sequence similar to the official Arduino shiftIn function structure in the Arduino Core (wiring.shift.c) , See issue 16 on github for full details. + +* Version 1.9.0 November 2022 + * Change made to Model 1/3 displayHex method as per pull request #19. + * Right aligned text mode added to (as per pull request #17) + * Model 1/3, methods displayIntNum and DisplayDecNumNibble + * Model 2 , methods DisplayDecNum, DisplayDecNumNibble & DisplayHexNum + * Previously it was just Left aligned text and added leading zeros. + diff --git a/keywords.txt b/keywords.txt index ae7e9bb..8e14015 100644 --- a/keywords.txt +++ b/keywords.txt @@ -31,5 +31,6 @@ ReadKey16 KEYWORD2 ReadKey16Two KEYWORD2 # Constants - +TMAlignTextRight LITERAL1 +TMAlignTextLeft LITERAL1 diff --git a/library.properties b/library.properties index ff54605..786f197 100755 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=TM1638plus -version=1.8.0 +version=1.9.0 author=Gavin Lyons maintainer=Gavin Lyons sentence=TM1638plus is an Arduino library to control TM1638 seven segment modules. diff --git a/src/TM1638plus.cpp b/src/TM1638plus.cpp index 5d78b44..c5d389f 100644 --- a/src/TM1638plus.cpp +++ b/src/TM1638plus.cpp @@ -81,22 +81,47 @@ void TM1638plus::setLEDs(uint16_t ledvalues) } -void TM1638plus::displayIntNum(unsigned long number, boolean leadingZeros) +void TM1638plus::displayIntNum(unsigned long number, boolean leadingZeros, AlignTextType_e TextAlignment) { char values[TM_DISPLAY_SIZE + 1]; - snprintf(values, TM_DISPLAY_SIZE + 1, leadingZeros ? "%08ld" : "%ld", number); + char TextDisplay[5] = "%"; + char TextLeft[3] = "ld"; + char TextRight[4] = "8ld"; + + if (TextAlignment == TMAlignTextLeft) + { + strcat(TextDisplay ,TextLeft); // %ld + }else if ( TextAlignment = TMAlignTextRight) + { + strcat(TextDisplay ,TextRight); // %8ld + } + + snprintf(values, TM_DISPLAY_SIZE + 1, leadingZeros ? "%08ld" : TextDisplay, number); displayText(values); } -void TM1638plus::DisplayDecNumNibble(uint16_t numberUpper, uint16_t numberLower, boolean leadingZeros) +void TM1638plus::DisplayDecNumNibble(uint16_t numberUpper, uint16_t numberLower, boolean leadingZeros, AlignTextType_e TextAlignment ) { - char valuesUpper[TM_DISPLAY_SIZE + 1]; - char valuesLower[TM_DISPLAY_SIZE/2 + 1]; - snprintf(valuesUpper, TM_DISPLAY_SIZE/2 + 1, leadingZeros ? "%04d" : "%d", numberUpper); - snprintf(valuesLower, TM_DISPLAY_SIZE/2 + 1, leadingZeros ? "%04d" : "%d", numberLower); - strcat(valuesUpper ,valuesLower); - displayText(valuesUpper); + char valuesUpper[TM_DISPLAY_SIZE + 1]; + char valuesLower[TM_DISPLAY_SIZE/2 + 1]; + char TextDisplay[5] = "%"; + char TextLeft[4] = "-4d"; + char TextRight[3] = "4d"; + + if (TextAlignment == TMAlignTextLeft) + { + strcat(TextDisplay ,TextLeft); // %-4d + }else if ( TextAlignment = TMAlignTextRight) + { + strcat(TextDisplay ,TextRight); // %4d + } + + snprintf(valuesUpper, TM_DISPLAY_SIZE/2 + 1, leadingZeros ? "%04d" : TextDisplay, numberUpper); + snprintf(valuesLower, TM_DISPLAY_SIZE/2 + 1, leadingZeros ? "%04d" : TextDisplay, numberLower); + + strcat(valuesUpper ,valuesLower); + displayText(valuesUpper); } void TM1638plus::displayText(const char *text) { diff --git a/src/TM1638plus.h b/src/TM1638plus.h index 6809a11..bdacc9b 100644 --- a/src/TM1638plus.h +++ b/src/TM1638plus.h @@ -19,6 +19,7 @@ #include "TM1638plus_common.h" + class TM1638plus { public: @@ -70,32 +71,39 @@ class TM1638plus { // i.e 0b01000001 will set g and a on. void display7Seg(uint8_t position, uint8_t value); - //Display an integer and leading zeros optional - void displayIntNum(unsigned long number, boolean leadingZeros = true); + // Display an integer and leading zeros optional + // Param 1 :: integer to display 2^32 + // Param 2 :: bool leading zeros , true on , false off + // Param 3 :: enum text alignment , left or right alignment + void displayIntNum(unsigned long number, boolean leadingZeros = true, AlignTextType_e = TMAlignTextLeft); - //Divides the display into two nibbles and displays a Decimal number in each. - //takes in two numbers 0-9999 for each nibble , and byte for decimal point display, - //and leading zeros optional - void DisplayDecNumNibble(uint16_t numberUpper, uint16_t numberLower, boolean leadingZeros = true); + // Divides the display into two nibbles and displays a Decimal number in each. + // takes in two numbers 0-9999 for each nibble , + // and leading zeros optional + // Param 1 :: upper nibble integer 2^16 + // Param 2 :: lower nibble integer 2^16 + // Param 3 :: bool leading zeros , true on , false off + // Param 4 :: enum text alignment , left or right alignment + void DisplayDecNumNibble(uint16_t numberUpper, uint16_t numberLower, boolean leadingZeros = true, AlignTextType_e = TMAlignTextLeft); - // Set the LEDs. passed one 16bit integer. - // MODEL 3: - //MSB byte for the green LEDs, LS byte for the red LEDs (0xgreenred) - //ie. 0xE007 1110 0000 0000 0111 results in L8-L0 GGGX XRRR, NOTE L8 is RHS on display - // MODEL 1: - // MSB byte 1 for red LED , LSB byte n/a set to 0x00 (0xleds, 0xXX) - //i.e 0xF100 1111 0000 L8-L0 RRRRXXX0 NOTE L8 is RHS on display - void setLEDs(uint16_t greenred); - - // Set an LED, pass it LED position 0-7 and value 0 or 1 , L1-L8 + // Set the LEDs. passed one 16bit integer. + // MODEL 3: + //MSB byte for the green LEDs, LS byte for the red LEDs (0xgreenred) + //ie. 0xE007 1110 0000 0000 0111 results in L8-L0 GGGX XRRR, NOTE L8 is RHS on display + // MODEL 1: + // MSB byte 1 for red LED , LSB byte n/a set to 0x00 (0xleds, 0xXX) + //i.e 0xF100 1111 0000 L8-L0 RRRRXXX0 NOTE L8 is RHS on display + void setLEDs(uint16_t greenred); + + // Set an LED, pass it LED position 0-7 and value 0 or 1 , L1-L8 void setLED(uint8_t position, uint8_t value); private: uint8_t _STROBE_IO; uint8_t _DATA_IO; uint8_t _CLOCK_IO; - void sendCommand(uint8_t value); - void sendData(uint8_t data); + void sendCommand(uint8_t value); + void sendData(uint8_t data); //This is used when running high freq CPU bool _HIGH_FREQ = false; TM1638plus_common TM_common; diff --git a/src/TM1638plus_Model2.cpp b/src/TM1638plus_Model2.cpp index 7ac43bb..a291862 100644 --- a/src/TM1638plus_Model2.cpp +++ b/src/TM1638plus_Model2.cpp @@ -78,29 +78,65 @@ void TM1638plus_Model2::brightness(uint8_t brightness) sendCommand(value); } -void TM1638plus_Model2::DisplayHexNum(uint16_t numberUpper, uint16_t numberLower, byte dots, boolean leadingZeros) +void TM1638plus_Model2::DisplayHexNum(uint16_t numberUpper, uint16_t numberLower, byte dots, boolean leadingZeros, AlignTextType_e TextAlignment ) { char valuesUpper[TM_DISPLAY_SIZE + 1]; char valuesLower[TM_DISPLAY_SIZE/2 + 1]; - snprintf(valuesUpper, TM_DISPLAY_SIZE/2 + 1, leadingZeros ? "%04X" : "%X", numberUpper); - snprintf(valuesLower, TM_DISPLAY_SIZE/2 + 1, leadingZeros ? "%04X" : "%X", numberLower); + char TextDisplay[5] = "%"; + char TextLeft[4] = "-4X"; + char TextRight[3] = "4X"; + + if (TextAlignment == TMAlignTextLeft) + { + strcat(TextDisplay ,TextLeft); // %-4X + }else if ( TextAlignment = TMAlignTextRight) + { + strcat(TextDisplay ,TextRight); // %4X + } + + snprintf(valuesUpper, TM_DISPLAY_SIZE/2 + 1, leadingZeros ? "%04X" : TextDisplay, numberUpper); + snprintf(valuesLower, TM_DISPLAY_SIZE/2 + 1, leadingZeros ? "%04X" : TextDisplay, numberLower); strcat(valuesUpper ,valuesLower); DisplayStr(valuesUpper, dots); } -void TM1638plus_Model2::DisplayDecNum(unsigned long number, byte dots, boolean leadingZeros) +void TM1638plus_Model2::DisplayDecNum(unsigned long number, byte dots, boolean leadingZeros, AlignTextType_e TextAlignment) { char values[TM_DISPLAY_SIZE + 1]; - snprintf(values, TM_DISPLAY_SIZE + 1, leadingZeros ? "%08ld" : "%ld", number); + char TextDisplay[5] = "%"; + char TextLeft[3] = "ld"; + char TextRight[4] = "8ld"; + + if (TextAlignment == TMAlignTextLeft) + { + strcat(TextDisplay ,TextLeft); // %ld + }else if ( TextAlignment = TMAlignTextRight) + { + strcat(TextDisplay ,TextRight); // %8ld + } + + snprintf(values, TM_DISPLAY_SIZE + 1, leadingZeros ? "%08ld" : TextDisplay, number); DisplayStr(values, dots); } -void TM1638plus_Model2::DisplayDecNumNibble(uint16_t numberUpper, uint16_t numberLower, byte dots, boolean leadingZeros) +void TM1638plus_Model2::DisplayDecNumNibble(uint16_t numberUpper, uint16_t numberLower, byte dots, boolean leadingZeros, AlignTextType_e TextAlignment ) { char valuesUpper[TM_DISPLAY_SIZE + 1]; char valuesLower[TM_DISPLAY_SIZE/2 + 1]; - snprintf(valuesUpper, TM_DISPLAY_SIZE/2 + 1, leadingZeros ? "%04d" : "%d", numberUpper); - snprintf(valuesLower, TM_DISPLAY_SIZE/2 + 1, leadingZeros ? "%04d" : "%d", numberLower); + char TextDisplay[5] = "%"; + char TextLeft[4] = "-4d"; + char TextRight[3] = "4d"; + + if (TextAlignment == TMAlignTextLeft) + { + strcat(TextDisplay ,TextLeft); // %-4d + }else if ( TextAlignment = TMAlignTextRight) + { + strcat(TextDisplay ,TextRight); // %4d + } + + snprintf(valuesUpper, TM_DISPLAY_SIZE/2 + 1, leadingZeros ? "%04d" : TextDisplay, numberUpper); + snprintf(valuesLower, TM_DISPLAY_SIZE/2 + 1, leadingZeros ? "%04d" : TextDisplay, numberLower); strcat(valuesUpper ,valuesLower); DisplayStr(valuesUpper, dots); } diff --git a/src/TM1638plus_Model2.h b/src/TM1638plus_Model2.h index e79c412..4b86df3 100644 --- a/src/TM1638plus_Model2.h +++ b/src/TM1638plus_Model2.h @@ -75,14 +75,22 @@ class TM1638plus_Model2 { // to set all segment "g" off (0x06,0X00) void DisplaySegments(uint8_t segment, uint8_t segmentValue); - // Display a Hexadecimal number ,takes a number and byte for decimal point display, leading zeros optional - // converts to string. - //void DisplayHexNum(unsigned long number, byte dots, boolean leadingZeros = true); - void DisplayHexNum(uint16_t numberUpper, uint16_t numberLower, byte dots, boolean leadingZeros = true); + // Display a Hexadecimal number , + // Param 1 :: upper nibble integer 2^16 + // Param 2 :: lower nibble integer 2^16 + // Param 3 :: byte dots turn on decimal points + // Param 4 :: bool leading zeros , true on , false off + // Param 5 :: enum text alignment , left or right alignment + // converts to string internally + void DisplayHexNum(uint16_t numberUpper, uint16_t numberLower, byte dots, boolean leadingZeros = true, AlignTextType_e = TMAlignTextLeft); - // Display a decimal number , takes a number and byte for decimal point display, leading zeros optional - // converts to string. - void DisplayDecNum(unsigned long number, byte dots, boolean leadingZeros = true); + // Display a decimal number , + // Param 1 :: 2^32 unsigned long + // Param 2 :: byte for decimal point display switch's on decimal point for those positions + // Param 3 :: leading zeros , true on , false off + // Param 4 :: enum text alignment , left or right + // converts to string internally + void DisplayDecNum(unsigned long number, byte dots, boolean leadingZeros = true, AlignTextType_e = TMAlignTextLeft); // Display a string , takes a string and byte for decimal point display // Takes in string , converts it to ASCII using the font and masks for the decimal point @@ -100,9 +108,12 @@ class TM1638plus_Model2 { void ASCIItoSegment(const byte values[]); //Divides the display into two nibbles and displays a Decimal number in each. - //takes in two numbers 0-9999 for each nibble , and byte for decimal point display, - //and leading zeros optional - void DisplayDecNumNibble(uint16_t numberUpper, uint16_t numberLower, byte dots, boolean leadingZeros = true); + // Param 1 :: upper nibble integer 2^16 + // Param 2 :: lower nibble integer 2^16 + // Param 3 :: byte dots turn on decimal points + // Param 4 :: bool leading zeros , true on , false off + // Param 5 :: enum text alignment , left or right alignment + void DisplayDecNumNibble(uint16_t numberUpper, uint16_t numberLower, byte dots, boolean leadingZeros = true, AlignTextType_e = TMAlignTextLeft); private: diff --git a/src/TM1638plus_common.h b/src/TM1638plus_common.h index aeea8d5..777618d 100644 --- a/src/TM1638plus_common.h +++ b/src/TM1638plus_common.h @@ -38,6 +38,12 @@ #define TM_HFIN_DELAY 1 // uS Delay used by shiftIn function for High-freq MCU #define TM_HFOUT_DELAY 1 // uS Delay used by shiftOut function for High-freq MCU +typedef enum +{ + TMAlignTextRight = 1, + TMAlignTextLeft = 2, +}AlignTextType_e; // Alignment of text + // font , map of ASCII values/table to 7-segment, offset to position 32. const PROGMEM unsigned char SevenSeg[] = { 0x00, /* (space) */