Skip to content

Commit

Permalink
0.3.6 TM1637_RT
Browse files Browse the repository at this point in the history
  • Loading branch information
RobTillaart committed Feb 27, 2023
1 parent 9a94d6d commit 2915f67
Show file tree
Hide file tree
Showing 9 changed files with 135 additions and 30 deletions.
10 changes: 8 additions & 2 deletions libraries/TM1637_RT/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
70 changes: 52 additions & 18 deletions libraries/TM1637_RT/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -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:

Expand Down Expand Up @@ -168,18 +198,22 @@ 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

- investigate if code can be optimized
- 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

Expand Down
14 changes: 13 additions & 1 deletion libraries/TM1637_RT/TM1637.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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};
Expand Down
17 changes: 15 additions & 2 deletions libraries/TM1637_RT/TM1637.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand All @@ -24,28 +24,41 @@ 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);
void displayFloat(float value);
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -62,9 +65,5 @@ void loop2()
}


// todo: make a HH:MM clock
// with the : flashing every second.



// -- END OF FILE --

Original file line number Diff line number Diff line change
@@ -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 --
2 changes: 2 additions & 0 deletions libraries/TM1637_RT/keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ displayFloat KEYWORD2
displayHex KEYWORD2
displayClear KEYWORD2

displayTime KEYWORD2

setBrightness KEYWORD2
getBrightness KEYWORD2

Expand Down
2 changes: 1 addition & 1 deletion libraries/TM1637_RT/library.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "*",
Expand Down
2 changes: 1 addition & 1 deletion libraries/TM1637_RT/library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=TM1637_RT
version=0.3.5
version=0.3.6
author=Rob Tillaart <[email protected]>
maintainer=Rob Tillaart <[email protected]>
sentence=TM1637 Library for Arduino.
Expand Down

0 comments on commit 2915f67

Please sign in to comment.