0.3.5 TM1637_RT

This commit is contained in:
rob tillaart 2023-02-18 13:28:46 +01:00
parent 9d6075d4f9
commit ae8aeb853f
12 changed files with 228 additions and 79 deletions

View File

@ -6,7 +6,7 @@ jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: arduino/arduino-lint-action@v1
with:
library-manager: update

View File

@ -8,7 +8,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: ruby/setup-ruby@v1
with:
ruby-version: 2.6

View File

@ -10,7 +10,7 @@ jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: json-syntax-check
uses: limitusus/json-syntax-check@v1
with:

View File

@ -5,26 +5,32 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).
## [0.3.4] - 2022-10-07
## [0.3.5] - 2023-02-18
- add **void displayFloat(float value, byte fixpoint)** Thanks to marshalab
- edd 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
- added **uint8_t asciiTo7Segment (char c)** thanks to radionerd
- updated documentation
## [0.3.3] - 2022-09-24
- added CHANGELOG.md
- added **begin()** to replace **init()** in due time.
- updated documentation
## [0.3.2] - 2022-04-16
- fix #15 support for 4 digits.
- tested on 4 digit (clock) display.
## [0.3.1] - 2021-12-29
- update library.json
- update license
- update readme.md
@ -32,30 +38,28 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- tested on 6 digits display (with decinal point).
## [0.3.0] - 2021-10-27
- improved keyscan - kudos to wfdudley
- update documentation
## [0.2.1] - 2021-10-07
----
## [0.2.1] - 2021-10-07
- add support for letters g-z; added keyscan()
- tested on ESP8266
## [0.2.0] - 2021-09-26
- add ESP32 support - kudos to alexthomazo
## [0.1.2] - 2021-04-16
----
## [0.1.2] - 2021-04-16
- update readme
- fix default values
## [0.1.1] - 2021-02-15
- first release
- added examples
## [0.1.0] - 2019-10-28
- initial version

View File

@ -1,6 +1,6 @@
MIT License
Copyright (c) 2019-2022 Rob Tillaart
Copyright (c) 2019-2023 Rob Tillaart
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

View File

@ -28,11 +28,13 @@ As the display is only tested with a 6 digit display, this is used as the defaul
- **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, 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 setBrightness(uint8_t b)** brightness = 0 .. 7 default = 3.
- **uint8_t getBrightness()** returns value set.
- **uint8_t keyscan(void)** scans the keyboard once and return result. The keyscan() function cannot detect multiple keys.
- **uint8_t keyscan(void)** scans the keyboard once and return result.
The keyscan() function cannot detect multiple keys.
**displayRaw()** can display multiple decimal points, by setting the high bit (0x80)
@ -46,7 +48,7 @@ Or you can use the pointPos argument to light just one decimal at that position.
- 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
**void displayPChar(char \*buff)** Attempts to display every ascii character 0x30 to 0x5F.
**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.
@ -61,7 +63,6 @@ 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
The library is tested with a 6 (=2x3) digit - decimal point - display and a 4 (=1x4) digit - clock - display.
@ -71,7 +72,7 @@ To adjust the order for a not supported display, the following function can be u
- **void setDigitOrder(uint8_t a, uint8_t b,... uint8_t h)** sets the order in which up to 8 digits should be clocked in.
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.
please open an issue on GitHub so it can be build in.
### Tuning function
@ -92,7 +93,9 @@ Feel free to file an issue to get your processor supported.
### Keyboard Scanner usage and notes
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:
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:
<CENTER>
<TABLE>
@ -163,16 +166,35 @@ See examples
## Future
### 0.4.0
#### Must
- remove obsolete **init()** from code (0.4.0)
#### Should
- remove obsolete **init()** from code
- investigate if code can be optimized
- performance measurement
### other
- 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
#### Could
- **keyScan()** camelCase ?
- add debug flag for test without hardware.
- simulate output to Serial? (HEX)?
- **displayTest()** function ?
#### Wont (unless requested)
- **rotate(bool rot = false)**
- 180 degree rotation of all digits for mounting
- reverse digit order
- flip every digit (function to overwrite the char array)
- **HUD(bool hud = false)** = Heads Up Display
- flip every digit

View File

@ -2,7 +2,7 @@
// FILE: TM1637.cpp
// AUTHOR: Rob Tillaart
// DATE: 2019-10-28
// VERSION: 0.3.4
// VERSION: 0.3.5
// PURPOSE: TM1637 library for Arduino
// URL: https://github.com/RobTillaart/TM1637_RT
@ -70,7 +70,7 @@ TM1637::TM1637()
}
// wrapper, will become obsolete 0.4.0.
// wrapper, init() will become obsolete 0.4.0.
void TM1637::init(uint8_t clockPin, uint8_t dataPin, uint8_t digits)
{
begin(clockPin, dataPin, digits);
@ -158,6 +158,51 @@ void TM1637::displayFloat(float value)
}
void TM1637::displayFloat(float value, uint8_t fixedPoint)
{
// DEBUG
// Serial.println(value);
uint8_t data[8] = { 16, 16, 16, 16, 16, 16, 16, 16};
float v = value;
int dpos = _digits - 1;
int last = _digits;
bool neg = (v < 0);
int point = fixedPoint + 1;
if (neg)
{
v = -v;
dpos--;
last--;
}
// v += 0.0001; // Bug fix for 12.999 <> 13.000
v += 0.001; // Bug fix for 12.99 <> 13.00
while (v >= 10)
{
v /= 10;
dpos--;
point++;
}
if (neg)
{
data[point] = 17; // minus sign;
}
for (int i = point - 1; i > -1; i--)
{
int d = v;
data[i] = d;
v -= d;
v *= 10;
}
displayRaw(data, fixedPoint);
}
void TM1637::displayHex(uint32_t value)
{
uint8_t data[8] = { 16, 16, 16, 16, 16, 16, 16, 16};
@ -180,13 +225,19 @@ void TM1637::displayClear()
}
void TM1637::setBrightness(uint8_t b)
void TM1637::setBrightness(uint8_t brightness)
{
_brightness = b;
_brightness = brightness;
if (_brightness > 0x07) _brightness = 0x07;
}
uint8_t TM1637::getBrightness()
{
return _brightness;
}
void TM1637::setDigitOrder(uint8_t a, uint8_t b,
uint8_t c, uint8_t d, uint8_t e,
uint8_t f, uint8_t g, uint8_t h)
@ -227,6 +278,16 @@ void TM1637::displayPChar( char * data )
void TM1637::displayRaw(uint8_t * data, uint8_t pointPos)
{
// DEBUG
// for (uint8_t d = 0; d < _digits; d++)
// {
// uint8_t x = data[_digits - d];
// if (x < 0x10) Serial.print('0');
// Serial.print(x, HEX);
// Serial.print(' ');
// }
// Serial.println();
uint8_t b = 0;
start();
@ -318,7 +379,7 @@ void TM1637::writeSync(uint8_t pin, uint8_t val)
digitalWrite(pin, val);
#if defined(ESP32)
nanoDelay(2);
nanoDelay(21); // delay(2) is not enough in practice.
#endif
// other processors may need other "nanoDelay(n)"
}
@ -326,6 +387,7 @@ void TM1637::writeSync(uint8_t pin, uint8_t val)
// keyscan results are reversed left for right from the data sheet.
// here are the values returned by keyscan():
//
// pin 2 3 4 5 6 7 8 9
// sg1 sg2 sg3 sg4 sg5 sg6 sg7 sg8
// 19 k1 0xf7 0xf6 0xf5 0xf4 0xf3 0xf2 0xf1 0xf0

View File

@ -3,7 +3,7 @@
// FILE: TM1637.h
// AUTHOR: Rob Tillaart
// DATE: 2019-10-28
// VERSION: 0.3.4
// VERSION: 0.3.5
// 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.4"))
#define TM1637_LIB_VERSION (F("0.3.5"))
class TM1637
@ -28,11 +28,12 @@ public:
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();
void setBrightness(uint8_t b);
uint8_t getBrightness() { return _brightness; };
void setBrightness(uint8_t brightness);
uint8_t getBrightness();
// tune the timing of writing bytes.
void setBitDelay(uint8_t bitDelay = 10) { _bitDelay = bitDelay; };

View File

@ -0,0 +1,59 @@
//
// FILE: TM1637_float_point.ino
// AUTHOR: marshalab, Rob Tillaart
// PURPOSE: demo TM1637 library
// URL: https://github.com/RobTillaart/TM1637
#include "TM1637.h"
TM1637 TM;
uint32_t start, stop;
volatile float f = 3.14159265;
void setup()
{
Serial.begin(115200);
Serial.println(__FILE__);
TM.begin(2, 3); // clockpin, datapin
TM.displayFloat(1.42425);
delay(2000);
TM.displayFloat(1.42425, 2);
delay(2000);
TM.displayFloat(-1.42425);
delay(2000);
TM.displayFloat(-1.42425, 2);
delay(2000);
TM.displayClear();
delay(5000);
}
void loop()
{
test();
delay(1000);
}
void test()
{
start = millis();
for (int i = 0; i < 1000; i++)
{
TM.displayFloat(f, 2); // there is loop overhead etc
f += 1;
}
stop = millis();
Serial.print("TIME:\t");
Serial.print(stop - start);
Serial.println(" ms");
}
// -- END OF FILE --

View File

@ -15,7 +15,7 @@
"type": "git",
"url": "https://github.com/RobTillaart/TM1637_RT"
},
"version": "0.3.4",
"version": "0.3.5",
"license": "MIT",
"frameworks": "arduino",
"platforms": "*",

View File

@ -1,5 +1,5 @@
name=TM1637_RT
version=0.3.4
version=0.3.5
author=Rob Tillaart <rob.tillaart@gmail.com>
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
sentence=TM1637 Library for Arduino.

View File

@ -1,7 +1,6 @@
//
// FILE: unit_test_001.cpp
// AUTHOR: Rob Tillaart
// VERSION: 0.1.0
// DATE: 2021-04-16
// PURPOSE: unit tests for the TM1637 library
// https://github.com/RobTillaart/TM_1637_RT
@ -97,4 +96,6 @@ unittest(test_set_bit_delay)
unittest_main()
// --------
// -- END OF FILE --