Skip to content

Commit 2915f67

Browse files
committed
0.3.6 TM1637_RT
1 parent 9a94d6d commit 2915f67

File tree

9 files changed

+135
-30
lines changed

9 files changed

+135
-30
lines changed

libraries/TM1637_RT/CHANGELOG.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,21 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
66
and this project adheres to [Semantic Versioning](http://semver.org/).
77

88

9+
## [0.3.6] - 2023-02-27
10+
- add **void displayTime(uint8_t hh, uint8_t mm, bool colon)**
11+
- add examples
12+
- update readme.md
13+
- update keywords.txt
14+
15+
916
## [0.3.5] - 2023-02-18
1017
- add **void displayFloat(float value, byte fixpoint)** Thanks to marshalab
11-
- edd example TM1637_float_point.ino
18+
- add example TM1637_float_point.ino
1219
- update readme.md
1320
- update GitHub actions
1421
- update license 2023
1522
- minor edits
1623

17-
1824
## [0.3.4] - 2022-10-07
1925
- added CHANGELOG.md
2026
- added **void displayPChar(char \* data)** thanks to radionerd

libraries/TM1637_RT/README.md

Lines changed: 52 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,29 +14,55 @@ Library for TM1637 driven displays and keyscans.
1414

1515
The TM1637 drives 7 segment displays and can also scan a 16 key keyboard.
1616

17-
Library is tested with Arduino UNO and a 6 digits display.
17+
Library is tested with Arduino UNO and a 6 digits display and 4 digit (clock) display.
1818

1919
ESP32 is supported since 0.2.0 see https://github.com/RobTillaart/TM1637_RT/pull/5
2020

2121

2222
## Interface
2323

24+
```cpp
25+
#include "TM1637.h"
26+
```
27+
28+
#### Core
29+
2430
- **TM1637()** constructor
25-
- **void begin(uint8_t clockPin, uint8_t dataPin, uint8_t digits = 6)** set up the connection of the pins to the display.
26-
As the display is only tested with a 6 digit display, this is used as the default of the digits parameter.
27-
- **void displayPChar(char \*buff)** display the buffer. Experimental - Tested on STM32 and Arduino Nano
31+
- **void begin(uint8_t clockPin, uint8_t dataPin, uint8_t digits = 6)**
32+
set up the connection of the pins to the display.
33+
As the display is only tested with a 6 digit display,
34+
this is used as the default of the digits parameter.
35+
36+
#### Display functions
37+
38+
- **void displayPChar(char \*buff)** display the buffer.
39+
Experimental - Tested on STM32 and Arduino Nano
2840
- **void displayRaw(uint8_t \* data, uint8_t pointPos)** low level write function.
2941
- **void displayInt(long value)** idem
30-
- **void displayFloat(float value)** idem
42+
- **void displayFloat(float value)** idem, position of point may vary!
3143
- **void displayFloat(float value, uint8_t fixedPoint)** display float with fixed point position.
3244
- **void displayHex(uint32_t value)** idem
3345
- **void displayClear()** writes spaces to all positions, effectively clearing the display.
46+
- **void displayTime(uint8_t hh, uint8_t mm, bool colon)** displays time format.
47+
The function does not check for overflow e.g. hh > 59 or mm > 59.
48+
Works only on 4 digit display.
49+
- hours + minutes HH:MM
50+
- minutes + seconds MM:SS
51+
- can also be used for temperature + humidity TT:HH or any pair of ints side by side.
52+
53+
#### Brightness
54+
3455
- **void setBrightness(uint8_t b)** brightness = 0 .. 7 default = 3.
3556
- **uint8_t getBrightness()** returns value set.
57+
58+
#### KeyScan
59+
3660
- **uint8_t keyscan(void)** scans the keyboard once and return result.
3761
The keyscan() function cannot detect multiple keys.
3862

3963

64+
#### DisplayRaw explained
65+
4066
**displayRaw()** can display multiple decimal points, by setting the high bit (0x80)
4167
in each character for which you wish to have a decimal lit.
4268
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.
4773
- a-f are coded as 0x0a-0x0f
4874
- g-z are coded as 0x12-0x25. Characters that cannot be represented in 7 segments render as blank.
4975
So "hello " is coded as 0x13, 0x0e, 0x17, 0x17, 0x1a, 0x10
50-
76+
77+
78+
#### displayPChar explained
79+
5180
**void displayPChar(char \*buff)** Attempts to display every ASCII character 0x30 to 0x5F.
5281
See example TM1637_custom.ino to insert your own 7 segment patterns.
5382
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
6392
- **void init(uint8_t clockPin, uint8_t dataPin, uint8_t digits = 6)** replaced by begin().
6493

6594

66-
### Display support
95+
#### Display support
6796

6897
The library is tested with a 6 (=2x3) digit - decimal point - display and a 4 (=1x4) digit - clock - display.
6998
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,
75104
please open an issue on GitHub so it can be build in.
76105

77106

78-
### Tuning function
107+
#### Tuning function
79108

80-
To tune the timing of writing bytes.
109+
To tune the timing of writing bytes.
110+
An UNO can gain ~100 micros per call by setting it to 0.
81111

82-
- **void setBitDelay(uint8_t bitDelay = 10)**
112+
- **void setBitDelay(uint8_t bitDelay = 10)**
83113
- **uint8_t getBitDelay()**
84114

85115

86-
### Tuning minimum pulse length
116+
#### Tuning minimum pulse length
87117

88118
The class has a conditional code part in writeSync to guarantee the length of pulses
89119
when the library is used with an ESP32. The function called there **nanoDelay(n)**
90120
needs manual adjustment depending upon processor frequency and time needed for a digitalWrite.
91121
Feel free to file an issue to get your processor supported.
92122

93-
### Keyboard Scanner usage and notes
94123

124+
## Keyboard Scanner usage and notes
95125

96-
Calling keyscan() returns a uint8_t, whose value is 0xff if no keys are being pressed at the time.
126+
Calling **keyscan()** returns a uint8_t, whose value is 0xff if no keys are being pressed at the time.
97127
The TM1637 can only see one key press at a time, and there is no "rollover".
98128
If a key is pressed, then the values are as follows:
99129

@@ -168,18 +198,22 @@ See examples
168198

169199
#### Must
170200

171-
- remove obsolete **init()** from code (0.4.0)
201+
- (0.4.0)
202+
- remove obsolete **init()** from code
203+
- **setLeadingZeros(bool on = false)** leading zeros flag, set data array to 0.
204+
- **getLeadingZeros()**
205+
172206

173207
#### Should
174208

175209
- investigate if code can be optimized
176210
- performance measurement
177211
- testing other platforms.
178212
- move code from .h to .cpp
179-
- **setLeadingZeros(bool on = false)** leading zeros flag
180-
- getter.
181-
- set data array to 0.
182-
- 0.4.0
213+
- add **void displayTwoInt(uint8_t x, uint8_t y, bool colon)**
214+
- should work for 4 and 6 digit displays
215+
- refactor readme.md
216+
183217

184218
#### Could
185219

libraries/TM1637_RT/TM1637.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// FILE: TM1637.cpp
33
// AUTHOR: Rob Tillaart
44
// DATE: 2019-10-28
5-
// VERSION: 0.3.5
5+
// VERSION: 0.3.6
66
// PURPOSE: TM1637 library for Arduino
77
// URL: https://github.com/RobTillaart/TM1637_RT
88

@@ -218,6 +218,18 @@ void TM1637::displayHex(uint32_t value)
218218
}
219219

220220

221+
void TM1637::displayTime(uint8_t hh, uint8_t mm, bool colon)
222+
{
223+
if (_digits != 4) return;
224+
uint8_t data[4] = { 16, 16, 16, 16 };
225+
data[3] = hh / 10;
226+
data[2] = hh % 10;
227+
data[1] = mm / 10;
228+
data[0] = mm % 10;
229+
displayRaw(data, colon ? 2 : -1);
230+
}
231+
232+
221233
void TM1637::displayClear()
222234
{
223235
uint8_t data[8] = { 16, 16, 16, 16, 16, 16, 16, 16};

libraries/TM1637_RT/TM1637.h

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// FILE: TM1637.h
44
// AUTHOR: Rob Tillaart
55
// DATE: 2019-10-28
6-
// VERSION: 0.3.5
6+
// VERSION: 0.3.6
77
// PUPROSE: TM1637 library for Arduino
88
// URL: https://github.com/RobTillaart/TM1637_RT
99

@@ -13,7 +13,7 @@
1313

1414
#include "Arduino.h"
1515

16-
#define TM1637_LIB_VERSION (F("0.3.5"))
16+
#define TM1637_LIB_VERSION (F("0.3.6"))
1717

1818

1919
class TM1637
@@ -24,28 +24,41 @@ class TM1637
2424
// replaces init()
2525
void begin(uint8_t clockPin, uint8_t dataPin, uint8_t digits = 6);
2626

27+
28+
// DISPLAY FUNCTIONS
2729
void displayPChar( char * buff );
2830
void displayRaw(uint8_t * data, uint8_t pointPos);
2931
void displayInt(long value);
3032
void displayFloat(float value);
3133
void displayFloat(float value, uint8_t fixedPoint);
3234
void displayHex(uint32_t value);
3335
void displayClear();
36+
// only works on 4 digit display with colon
37+
void displayTime(uint8_t hh, uint8_t mm, bool colon);
38+
3439

40+
// BRIGHTNESS
3541
void setBrightness(uint8_t brightness);
3642
uint8_t getBrightness();
3743

44+
45+
// BIT DELAY
3846
// tune the timing of writing bytes.
3947
void setBitDelay(uint8_t bitDelay = 10) { _bitDelay = bitDelay; };
4048
uint8_t getBitDelay() { return _bitDelay; };
49+
50+
// KEY SCAN
4151
uint8_t keyscan(void);
4252

53+
54+
// CONFIGURATION
4355
// the order the individual digits must be sent to the display.
4456
void setDigitOrder(uint8_t a = 0, uint8_t b = 1,
4557
uint8_t c = 2, uint8_t d = 3,
4658
uint8_t e = 4, uint8_t f = 5,
4759
uint8_t g = 6, uint8_t h = 7);
4860

61+
4962
// OBSOLETE
5063
// init will be replaced by begin() in the future (0.4.0)
5164
void init(uint8_t clockPin, uint8_t dataPin, uint8_t digits = 6);

libraries/TM1637_RT/examples/TM1637_clock_4digits/TM1637_clock_4digits.ino

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
// AUTHOR: Rob Tillaart
44
// PURPOSE: demo TM1637 library
55
// URL: https://github.com/RobTillaart/TM1637
6+
//
7+
// Since 0.3.6 the library has the function displayTime(hh, mm, colon).
8+
// so part of this sketch is "historical".
69

710

811
#include "TM1637.h"
@@ -62,9 +65,5 @@ void loop2()
6265
}
6366

6467

65-
// todo: make a HH:MM clock
66-
// with the : flashing every second.
67-
68-
69-
7068
// -- END OF FILE --
69+
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
//
2+
// FILE: TM1637_displayTime.ino
3+
// AUTHOR: Rob Tillaart
4+
// PURPOSE: demo TM1637 library
5+
// URL: https://github.com/RobTillaart/TM1637
6+
7+
8+
#include "TM1637.h"
9+
10+
TM1637 TM;
11+
12+
uint32_t start, stop;
13+
14+
void setup()
15+
{
16+
Serial.begin(115200);
17+
Serial.println(__FILE__);
18+
19+
TM.begin(7, 6, 4); // clockpin, datapin, #digits
20+
21+
delay(10);
22+
start = micros();
23+
TM.displayTime(59, 59, true);
24+
stop = micros();
25+
Serial.println(stop - start);
26+
}
27+
28+
29+
void loop()
30+
{
31+
uint32_t now = 523 + millis() / 1000;
32+
uint8_t hh = now / 60;
33+
uint8_t mm = now - hh * 60;
34+
bool colon = (millis() % 1000 < 500);
35+
TM.displayTime(hh, mm, colon);
36+
}
37+
38+
39+
// -- END OF FILE --

libraries/TM1637_RT/keywords.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ displayFloat KEYWORD2
1515
displayHex KEYWORD2
1616
displayClear KEYWORD2
1717

18+
displayTime KEYWORD2
19+
1820
setBrightness KEYWORD2
1921
getBrightness KEYWORD2
2022

libraries/TM1637_RT/library.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"type": "git",
1616
"url": "https://github.com/RobTillaart/TM1637_RT"
1717
},
18-
"version": "0.3.5",
18+
"version": "0.3.6",
1919
"license": "MIT",
2020
"frameworks": "arduino",
2121
"platforms": "*",

libraries/TM1637_RT/library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=TM1637_RT
2-
version=0.3.5
2+
version=0.3.6
33
author=Rob Tillaart <[email protected]>
44
maintainer=Rob Tillaart <[email protected]>
55
sentence=TM1637 Library for Arduino.

0 commit comments

Comments
 (0)