From 2915f67bd0c39a754a017be7ed2d876ba3911c3d Mon Sep 17 00:00:00 2001 From: rob tillaart Date: Mon, 27 Feb 2023 20:45:02 +0100 Subject: [PATCH] 0.3.6 TM1637_RT --- libraries/TM1637_RT/CHANGELOG.md | 10 ++- libraries/TM1637_RT/README.md | 70 ++++++++++++++----- libraries/TM1637_RT/TM1637.cpp | 14 +++- libraries/TM1637_RT/TM1637.h | 17 ++++- .../TM1637_clock_4digits.ino | 9 ++- .../TM1637_displayTime/TM1637_displayTime.ino | 39 +++++++++++ libraries/TM1637_RT/keywords.txt | 2 + libraries/TM1637_RT/library.json | 2 +- libraries/TM1637_RT/library.properties | 2 +- 9 files changed, 135 insertions(+), 30 deletions(-) create mode 100644 libraries/TM1637_RT/examples/TM1637_displayTime/TM1637_displayTime.ino diff --git a/libraries/TM1637_RT/CHANGELOG.md b/libraries/TM1637_RT/CHANGELOG.md index abd97e4fe..7c79aaf3a 100644 --- a/libraries/TM1637_RT/CHANGELOG.md +++ b/libraries/TM1637_RT/CHANGELOG.md @@ -6,15 +6,21 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## [0.3.6] - 2023-02-27 +- add **void displayTime(uint8_t hh, uint8_t mm, bool colon)** +- add examples +- update readme.md +- update keywords.txt + + ## [0.3.5] - 2023-02-18 - add **void displayFloat(float value, byte fixpoint)** Thanks to marshalab -- edd example TM1637_float_point.ino +- add example TM1637_float_point.ino - update readme.md - update GitHub actions - update license 2023 - minor edits - ## [0.3.4] - 2022-10-07 - added CHANGELOG.md - added **void displayPChar(char \* data)** thanks to radionerd diff --git a/libraries/TM1637_RT/README.md b/libraries/TM1637_RT/README.md index 3184d5463..1954e54e7 100644 --- a/libraries/TM1637_RT/README.md +++ b/libraries/TM1637_RT/README.md @@ -14,29 +14,55 @@ Library for TM1637 driven displays and keyscans. The TM1637 drives 7 segment displays and can also scan a 16 key keyboard. -Library is tested with Arduino UNO and a 6 digits display. +Library is tested with Arduino UNO and a 6 digits display and 4 digit (clock) display. ESP32 is supported since 0.2.0 see https://github.com/RobTillaart/TM1637_RT/pull/5 ## Interface +```cpp +#include "TM1637.h" +``` + +#### Core + - **TM1637()** constructor -- **void begin(uint8_t clockPin, uint8_t dataPin, uint8_t digits = 6)** set up the connection of the pins to the display. -As the display is only tested with a 6 digit display, this is used as the default of the digits parameter. -- **void displayPChar(char \*buff)** display the buffer. Experimental - Tested on STM32 and Arduino Nano +- **void begin(uint8_t clockPin, uint8_t dataPin, uint8_t digits = 6)** + set up the connection of the pins to the display. +As the display is only tested with a 6 digit display, +this is used as the default of the digits parameter. + +#### Display functions + +- **void displayPChar(char \*buff)** display the buffer. +Experimental - Tested on STM32 and Arduino Nano - **void displayRaw(uint8_t \* data, uint8_t pointPos)** low level write function. - **void displayInt(long value)** idem -- **void displayFloat(float value)** idem +- **void displayFloat(float value)** idem, position of point may vary! - **void displayFloat(float value, uint8_t fixedPoint)** display float with fixed point position. - **void displayHex(uint32_t value)** idem - **void displayClear()** writes spaces to all positions, effectively clearing the display. +- **void displayTime(uint8_t hh, uint8_t mm, bool colon)** displays time format. +The function does not check for overflow e.g. hh > 59 or mm > 59. +Works only on 4 digit display. + - hours + minutes HH:MM + - minutes + seconds MM:SS + - can also be used for temperature + humidity TT:HH or any pair of ints side by side. + +#### Brightness + - **void setBrightness(uint8_t b)** brightness = 0 .. 7 default = 3. - **uint8_t getBrightness()** returns value set. + +#### KeyScan + - **uint8_t keyscan(void)** scans the keyboard once and return result. The keyscan() function cannot detect multiple keys. +#### DisplayRaw explained + **displayRaw()** can display multiple decimal points, by setting the high bit (0x80) in each character for which you wish to have a decimal lit. Or you can use the pointPos argument to light just one decimal at that position. @@ -47,7 +73,10 @@ Or you can use the pointPos argument to light just one decimal at that position. - a-f are coded as 0x0a-0x0f - g-z are coded as 0x12-0x25. Characters that cannot be represented in 7 segments render as blank. So "hello " is coded as 0x13, 0x0e, 0x17, 0x17, 0x1a, 0x10 - + + +#### displayPChar explained + **void displayPChar(char \*buff)** Attempts to display every ASCII character 0x30 to 0x5F. See example TM1637_custom.ino to insert your own 7 segment patterns. Also displayed are ' ' , '.' and '-' . Decimal points may also be displayed by setting the character sign bit. @@ -63,7 +92,7 @@ Routine **button_poll()** in the same example shows one way of polling and de-bo - **void init(uint8_t clockPin, uint8_t dataPin, uint8_t digits = 6)** replaced by begin(). -### Display support +#### Display support The library is tested with a 6 (=2x3) digit - decimal point - display and a 4 (=1x4) digit - clock - display. At low level these displays differ in the order the digits have to be clocked in. @@ -75,25 +104,26 @@ If you have a (7 segment) display that is not supported by the library, please open an issue on GitHub so it can be build in. -### Tuning function +#### Tuning function -To tune the timing of writing bytes. +To tune the timing of writing bytes. +An UNO can gain ~100 micros per call by setting it to 0. -- **void setBitDelay(uint8_t bitDelay = 10)** +- **void setBitDelay(uint8_t bitDelay = 10)** - **uint8_t getBitDelay()** -### Tuning minimum pulse length +#### Tuning minimum pulse length The class has a conditional code part in writeSync to guarantee the length of pulses when the library is used with an ESP32. The function called there **nanoDelay(n)** needs manual adjustment depending upon processor frequency and time needed for a digitalWrite. Feel free to file an issue to get your processor supported. -### Keyboard Scanner usage and notes +## Keyboard Scanner usage and notes -Calling keyscan() returns a uint8_t, whose value is 0xff if no keys are being pressed at the time. +Calling **keyscan()** returns a uint8_t, whose value is 0xff if no keys are being pressed at the time. The TM1637 can only see one key press at a time, and there is no "rollover". If a key is pressed, then the values are as follows: @@ -168,7 +198,11 @@ See examples #### Must -- remove obsolete **init()** from code (0.4.0) +- (0.4.0) + - remove obsolete **init()** from code + - **setLeadingZeros(bool on = false)** leading zeros flag, set data array to 0. + - **getLeadingZeros()** + #### Should @@ -176,10 +210,10 @@ See examples - performance measurement - testing other platforms. - move code from .h to .cpp -- **setLeadingZeros(bool on = false)** leading zeros flag - - getter. - - set data array to 0. - - 0.4.0 +- add **void displayTwoInt(uint8_t x, uint8_t y, bool colon)** + - should work for 4 and 6 digit displays +- refactor readme.md + #### Could diff --git a/libraries/TM1637_RT/TM1637.cpp b/libraries/TM1637_RT/TM1637.cpp index dea6f43f5..1a3e30864 100644 --- a/libraries/TM1637_RT/TM1637.cpp +++ b/libraries/TM1637_RT/TM1637.cpp @@ -2,7 +2,7 @@ // FILE: TM1637.cpp // AUTHOR: Rob Tillaart // DATE: 2019-10-28 -// VERSION: 0.3.5 +// VERSION: 0.3.6 // PURPOSE: TM1637 library for Arduino // URL: https://github.com/RobTillaart/TM1637_RT @@ -218,6 +218,18 @@ void TM1637::displayHex(uint32_t value) } +void TM1637::displayTime(uint8_t hh, uint8_t mm, bool colon) +{ + if (_digits != 4) return; + uint8_t data[4] = { 16, 16, 16, 16 }; + data[3] = hh / 10; + data[2] = hh % 10; + data[1] = mm / 10; + data[0] = mm % 10; + displayRaw(data, colon ? 2 : -1); +} + + void TM1637::displayClear() { uint8_t data[8] = { 16, 16, 16, 16, 16, 16, 16, 16}; diff --git a/libraries/TM1637_RT/TM1637.h b/libraries/TM1637_RT/TM1637.h index 12d4d0b93..918121387 100644 --- a/libraries/TM1637_RT/TM1637.h +++ b/libraries/TM1637_RT/TM1637.h @@ -3,7 +3,7 @@ // FILE: TM1637.h // AUTHOR: Rob Tillaart // DATE: 2019-10-28 -// VERSION: 0.3.5 +// VERSION: 0.3.6 // PUPROSE: TM1637 library for Arduino // URL: https://github.com/RobTillaart/TM1637_RT @@ -13,7 +13,7 @@ #include "Arduino.h" -#define TM1637_LIB_VERSION (F("0.3.5")) +#define TM1637_LIB_VERSION (F("0.3.6")) class TM1637 @@ -24,6 +24,8 @@ class TM1637 // replaces init() void begin(uint8_t clockPin, uint8_t dataPin, uint8_t digits = 6); + + // DISPLAY FUNCTIONS void displayPChar( char * buff ); void displayRaw(uint8_t * data, uint8_t pointPos); void displayInt(long value); @@ -31,21 +33,32 @@ class TM1637 void displayFloat(float value, uint8_t fixedPoint); void displayHex(uint32_t value); void displayClear(); + // only works on 4 digit display with colon + void displayTime(uint8_t hh, uint8_t mm, bool colon); + + // BRIGHTNESS void setBrightness(uint8_t brightness); uint8_t getBrightness(); + + // BIT DELAY // tune the timing of writing bytes. void setBitDelay(uint8_t bitDelay = 10) { _bitDelay = bitDelay; }; uint8_t getBitDelay() { return _bitDelay; }; + + // KEY SCAN uint8_t keyscan(void); + + // CONFIGURATION // the order the individual digits must be sent to the display. void setDigitOrder(uint8_t a = 0, uint8_t b = 1, uint8_t c = 2, uint8_t d = 3, uint8_t e = 4, uint8_t f = 5, uint8_t g = 6, uint8_t h = 7); + // OBSOLETE // init will be replaced by begin() in the future (0.4.0) void init(uint8_t clockPin, uint8_t dataPin, uint8_t digits = 6); diff --git a/libraries/TM1637_RT/examples/TM1637_clock_4digits/TM1637_clock_4digits.ino b/libraries/TM1637_RT/examples/TM1637_clock_4digits/TM1637_clock_4digits.ino index 2d195acc8..6f060a654 100644 --- a/libraries/TM1637_RT/examples/TM1637_clock_4digits/TM1637_clock_4digits.ino +++ b/libraries/TM1637_RT/examples/TM1637_clock_4digits/TM1637_clock_4digits.ino @@ -3,6 +3,9 @@ // AUTHOR: Rob Tillaart // PURPOSE: demo TM1637 library // URL: https://github.com/RobTillaart/TM1637 +// +// Since 0.3.6 the library has the function displayTime(hh, mm, colon). +// so part of this sketch is "historical". #include "TM1637.h" @@ -62,9 +65,5 @@ void loop2() } -// todo: make a HH:MM clock -// with the : flashing every second. - - - // -- END OF FILE -- + diff --git a/libraries/TM1637_RT/examples/TM1637_displayTime/TM1637_displayTime.ino b/libraries/TM1637_RT/examples/TM1637_displayTime/TM1637_displayTime.ino new file mode 100644 index 000000000..2a9b2bb9a --- /dev/null +++ b/libraries/TM1637_RT/examples/TM1637_displayTime/TM1637_displayTime.ino @@ -0,0 +1,39 @@ +// +// FILE: TM1637_displayTime.ino +// AUTHOR: Rob Tillaart +// PURPOSE: demo TM1637 library +// URL: https://github.com/RobTillaart/TM1637 + + +#include "TM1637.h" + +TM1637 TM; + +uint32_t start, stop; + +void setup() +{ + Serial.begin(115200); + Serial.println(__FILE__); + + TM.begin(7, 6, 4); // clockpin, datapin, #digits + + delay(10); + start = micros(); + TM.displayTime(59, 59, true); + stop = micros(); + Serial.println(stop - start); +} + + +void loop() +{ + uint32_t now = 523 + millis() / 1000; + uint8_t hh = now / 60; + uint8_t mm = now - hh * 60; + bool colon = (millis() % 1000 < 500); + TM.displayTime(hh, mm, colon); +} + + +// -- END OF FILE -- diff --git a/libraries/TM1637_RT/keywords.txt b/libraries/TM1637_RT/keywords.txt index 67df0c0af..8840afa8d 100644 --- a/libraries/TM1637_RT/keywords.txt +++ b/libraries/TM1637_RT/keywords.txt @@ -15,6 +15,8 @@ displayFloat KEYWORD2 displayHex KEYWORD2 displayClear KEYWORD2 +displayTime KEYWORD2 + setBrightness KEYWORD2 getBrightness KEYWORD2 diff --git a/libraries/TM1637_RT/library.json b/libraries/TM1637_RT/library.json index 97a3a030e..32094e887 100644 --- a/libraries/TM1637_RT/library.json +++ b/libraries/TM1637_RT/library.json @@ -15,7 +15,7 @@ "type": "git", "url": "https://github.com/RobTillaart/TM1637_RT" }, - "version": "0.3.5", + "version": "0.3.6", "license": "MIT", "frameworks": "arduino", "platforms": "*", diff --git a/libraries/TM1637_RT/library.properties b/libraries/TM1637_RT/library.properties index f879e21a4..6b8f33f69 100644 --- a/libraries/TM1637_RT/library.properties +++ b/libraries/TM1637_RT/library.properties @@ -1,5 +1,5 @@ name=TM1637_RT -version=0.3.5 +version=0.3.6 author=Rob Tillaart maintainer=Rob Tillaart sentence=TM1637 Library for Arduino.