0.3.9 TM1637_RT

This commit is contained in:
Rob Tillaart 2023-11-23 13:39:41 +01:00
parent 9267104c15
commit 0c1e250fc4
19 changed files with 261 additions and 148 deletions

View File

@ -6,6 +6,17 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).
## [0.3.9] - 2023-11-22
- update readme.md
- section about hardware performance (Kudos to SteveMicroCode #29)
- badges to platformIO + issues
- improve related section
- update keywords.txt
- **keyScan()** replaces keyscan() => prefer camelCase (prep 0.4.0)
- patched examples.
- minor edits
## [0.3.8] - 2023-07-15
- fix #27
- replaced function data\[8] with a class level data\[8].
@ -17,12 +28,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- fix bug in **displayRaw()** (add bool hasPoint).
- update readme.md
## [0.3.7] - 2023-04-17
- move code from .h to .cpp
- add **displayTwoInt(int ll, int rr, bool colon = true)**
- add **displayCelsius(int temp, bool colon = false)**
- add '°' degree character (18)
- add '°' degree character (18)
- add examples
- update readme.md

View File

@ -1,8 +1,12 @@
[![Arduino CI](https://github.com/robtillaart/TM1637_RT/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci)
[![Arduino CI](https://github.com/RobTillaart/TM1637_RT/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci)
[![Arduino-lint](https://github.com/RobTillaart/TM1637_RT/actions/workflows/arduino-lint.yml/badge.svg)](https://github.com/RobTillaart/TM1637_RT/actions/workflows/arduino-lint.yml)
[![JSON check](https://github.com/RobTillaart/TM1637_RT/actions/workflows/jsoncheck.yml/badge.svg)](https://github.com/RobTillaart/TM1637_RT/actions/workflows/jsoncheck.yml)
[![GitHub issues](https://img.shields.io/github/issues/RobTillaart/TM1637_RT.svg)](https://github.com/RobTillaart/TM1637_RT/issues)
[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/TM1637_RT/blob/master/LICENSE)
[![GitHub release](https://img.shields.io/github/release/RobTillaart/TM1637_RT.svg?maxAge=3600)](https://github.com/RobTillaart/TM1637_RT/releases)
[![PlatformIO Registry](https://badges.registry.platformio.org/packages/robtillaart/library/TM1637_RT.svg)](https://registry.platformio.org/libraries/robtillaart/TM1637_RT)
# TM1637
@ -14,7 +18,9 @@ Library for TM1637 driven displays and key scans.
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 and 4 digit (clock) display.
The library is mainly tested with Arduino UNO, both a 6 digits display and 4 digit (clock) display.
The TM1637 can scan max 2 rows and 8 columns or a smaller keyboard.
It is therefore not possible to scan a "standard" 3x4 or 4x4 matrix keypad.
ESP32 is supported since 0.2.0 see https://github.com/RobTillaart/TM1637_RT/pull/5
@ -22,6 +28,37 @@ ESP32 is supported since 0.2.0 see https://github.com/RobTillaart/TM1637_RT/pull
#### Related
- https://docs.wokwi.com/parts/wokwi-tm1637-7segment#simulator-examples
- https://github.com/SteveMicroCode/PIC-TM1637-Library-CodeOn
- includes interesting hardware notes.
- https://github.com/RobTillaart/HT16K33
- https://github.com/RobTillaart/AnalogKeypad
- https://github.com/RobTillaart/I2CKeyPad
- https://github.com/RobTillaart/I2CKeyPad8x8
#### Hardware connection and performance
From tests of SteveMicroCode (See #29) it became clear that the proposed hardware in the
datasheet is very robust but slow. See page 8 datasheet.
Leaving out the 100 pF capacitors on the CLK and DIO line, or dimension them smaller,
allows for faster communication and thus more efficient CPU use.
More about his tests see - https://github.com/SteveMicroCode/PIC-TM1637-Library-CodeOn
Additional tests of wfdudley (See Keyboard Scanner section) shows that reducing
the pull up resistor from 10 KΩ to 1000 Ω improves the signal quality.
This too allows for faster communication and efficient CPU use.
Datasheet page 3: _and the clock frequency should be less than 250K_ (KHz)
This implies that the **setBitDelay()** could be set much lower than the default 10 micro
seconds of the library. On "slower" platforms it might even be 0.
However it is always important to do your own tests if you want to tweak performance
beyond the specifications of the datasheet.
Interference from other electronic components is often nearby, and if you need longer
cables consider shielded ones.
If you have additional performance tweaks, please let me know.
Note: Ω = ALT-234
## Interface
@ -78,13 +115,17 @@ Applications include:
- meters + centimetre MM:CC (e.g distance sensor)
- feet + inches FF:II
- any pair of integers (-9 .. 99) side by side.
#### Display functions III
- **void displayCelsius(int temp, bool colon = false)** print temperature in **Celsius** format.
The function allows a range from -9 .. 99 + °C.
The function allows a range from -9 .. 99 + °C.
The colon is default false.
Works only on a 4 digit display.
Colon can be used e.g. to indicate under- or overflow, or any other threshold.
- **void displayFahrenheit(int temp, bool colon = false)** print temperature in **Fahrenheit** format.
The function allows a range from -9 .. 99 + °F.
The function allows a range from -9 .. 99 + °F.
The colon is default false.
Works only on a 4 digit display.
Colon can be used e.g. to indicate under- or overflow, or any other threshold.
@ -93,16 +134,19 @@ Colon can be used e.g. to indicate under- or overflow, or any other threshold.
TM.displayCelsius(temperature, (temperature < -9) || (temperature > 99));
```
##### Notes on temperature
Note that the effective range of Celsius and Fahrenheit differs.
When Fahrenheit goes from -9 to 99 Celsius goes from -26 to 37 (etc).
Note that the effective range of C and F differs
| F | C | F | C |
|:-----:|:-----:|:-----:|:-----:|
| -9 | -26 | 16 | -9 |
| 99 | 37 | 210 | 99 |
| F | C | | C | F |
|:-----:|:-----:|:----:|:-----:|:-----:|
| -9 | -26 | | -9 | 16 |
| 99 | 37 | | 99 | 210 |
Need to think about a 3 digit temperature to extend the range -99 .. 999
or to have one decimal.
A three digit temperature, e.g. range -99 .. 999, or -9.9 .. 99.9 would be possible.
Then one has to leave out either the ° character or the C/F.
As the C/F is far more informative, the choice is fairly easy.
Question is how to API should change, new function of new behaviour?
See future.
#### Brightness
@ -113,8 +157,8 @@ or to have one decimal.
#### KeyScan
- **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 explained
@ -203,10 +247,13 @@ 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
Calling **keyscan()** returns a uint8_t, whose value is 0xff if no keys are being pressed at the time.
- Kudos to wfdudley for this section - See #11
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:
@ -214,7 +261,7 @@ If a key is pressed, then the values are as follows:
<TABLE>
<TR>
<TD colspan = 10 align="center">
keyscan results are reversed left for right from the data sheet.
keyScan results are reversed left for right from the data sheet.
</TD>
</TR>
<TR>
@ -231,41 +278,69 @@ If a key is pressed, then the values are as follows:
</TR>
</TABLE>
</CENTER>
<P>
To modify a "generic" TM1637 board for use with a keyboard, you must add connections to either or both of pins 19 and 20 (these are the "row" selects) and then to as many of pins 2 through 9 (the "columns") as needed. It is easiest to connect to the "column pins" (2-9) by picking them up where they connect to the LED displays (see second photo). Generic keyboards that are a 4x4 matrix won't work; the TM1637 can only scan a 2x8 matrix. Of course, fewer keys are acceptable; I use a 1x4 keyboard in my projects.
</P>
<P>
Further, the TM1637 chip needs a fairly hefty pull-up on the DIO pin for the keyscan() routine to work. There is no pull-up in the TM1637 itself, and the clone boards don't seem to have one either, despite the data sheet calling for 10K ohms pull-ups on DIO and CLOCK. 10K is too weak anyway. The slow rise-time of the DIO signal means that the "true/high" value isn't reached fast enough and reliably enough for the processor to read it correctly. The new pull-up reduces the rise time of the signal, so that true/high values are achieved in a few microseconds. I find that a 1K (1000) ohm resistor from DIO to 3.3 v works well. This is perfect with a 3.3 volt processor like the ESP8266 or ESP32, and a 5V Atmega 328 ("Arduino UNO") family processor is happy with that as well.
</P>
<P>
The TM1637 boards want to be run off of 5 volts, regardless of what the processor voltage is. Their logic levels are compatible with 3.3 volt processors, and they need 5 volts to make sure the LEDs light up.
</P>
The unmodified generic TM1637 board (front and back).</br>
To modify a "generic" TM1637 board for use with a keyboard, you must add connections to either
or both of pins 19 and 20 (these are the "row" selects) and then to as many of pins 2 through 9
(the "columns") as needed. It is easiest to connect to the "column pins" (2-9) by picking them
up where they connect to the LED displays (see second photo).
Generic keyboards that are a 4x4 matrix won't work; the TM1637 can only scan a 2x8 matrix.
Of course, fewer keys are acceptable; I use a 1x4 keyboard in my projects.
Further, the TM1637 chip needs a fairly hefty pull-up on the DIO pin for the keyScan() routine to work.
There is no pull-up in the TM1637 itself, and the clone boards don't seem to have one either,
despite the data sheet calling for 10K ohms pull-ups on DIO and CLOCK. 10K is too weak anyway.
The slow rise-time of the DIO signal means that the "true/high" value isn't reached fast enough and
reliably enough for the processor to read it correctly. The new pull-up reduces the rise time of the signal,
so that true/high values are achieved in a few microseconds.
I find that a 1K (1000) ohm resistor from DIO to 3.3 v works well. This is perfect with a 3.3 volt processor
like the ESP8266 or ESP32, and a 5V Atmega 328 ("Arduino UNO") family processor is happy with that as well.
The TM1637 boards want to be run off of 5 volts, regardless of what the processor voltage is.
Their logic levels are compatible with 3.3 volt processors, and they need 5 volts to make sure the LEDs light up.
The unmodified generic TM1637 board (front and back).
<IMG src="images/unmodified.jpg">
</br>
The modified generic TM1637 board with connector for 1x4 keyboard. The blue wire is bringing out pin 19 (k1). Four segments/columns are picked up from the LEDs.</br>
The modified generic TM1637 board with connector for 1x4 keyboard.
The blue wire is bringing out pin 19 (k1).
Four segments/columns are picked up from the LEDs.
<IMG src="images/modified.jpg">
</br>
The 4 button keyboard plugged into the TM1637 board.</br>
<IMG src="images/disp_plus_kbd.jpg"></br>
</br>
Scope photo showing slow rise time of DIO pin (upper trace) on the unmodified TM1637. The lower trace is the CLK. The 8 fast CLK pulses on the left represent the 0x42 command to read keyboard being sent to the TM1637.</br>
<IMG src="images/slow_rise.jpg"></br>
</br>
Scope photo showing faster rise time of DIO pin (upper trace) with 1000 ohm pull-up on DIO. In both scope photos, the F5 key is pressed; the bits are least significant bit (LSB) first, so read as 10101111 left to right.</br>
<IMG src="images/fast_rise.jpg"></br>
The scope photos were taken using the TM1637_keyscan_raw example, with the scope trigger hooked to the TRIGGER pin, and the two channel probes hooked to DIO and CLK. Vertical sensitivity is 2v/division, horizontal timebase is 20usec/division.
The 4 button keyboard plugged into the TM1637 board.
<IMG src="images/disp_plus_kbd.jpg">
## Keyscan
Scope photo showing slow rise time of DIO pin (upper trace) on the unmodified TM1637.
The lower trace is the CLK. The 8 fast CLK pulses on the left represent the 0x42 command
to read keyboard being sent to the TM1637.
<IMG src="images/slow_rise.jpg">
Scope photo showing faster rise time of DIO pin (upper trace) with 1000 ohm pull-up on DIO.
In both scope photos, the F5 key is pressed; the bits are least significant bit (LSB) first,
so read as 10101111 left to right.
<IMG src="images/fast_rise.jpg">
The scope photos were taken using the TM1637_keyscan_raw example, with the scope trigger
hooked to the TRIGGER pin, and the two channel probes hooked to DIO and CLK.
Vertical sensitivity is 2v/division, horizontal timebase is 20usec/division.
## KeyScan
Implemented in version 0.3.0 Please read the datasheet to understand the limitations.
```
// NOTE:
// on the TM1637 boards tested by @wfdudley, keyscan() works well
// if you add a 910 ohm or 1 Kohm pull-up resistor from DIO to 3.3v
// on the TM1637 boards tested by @wfdudley, keyScan() works well
// if you add a 910 ohm or 1000 ohm pull-up resistor from DIO to 3.3v
// This reduces the rise time of the DIO signal when reading the key info.
// If one only uses the pull-up inside the microcontroller,
// the rise time is too long for the data to be read reliably.
@ -283,32 +358,34 @@ See examples
- (0.4.0)
- remove obsolete **init()** from code
- remove keyscan() => keyScan()
- **setLeadingZeros(bool on = false)** leading zeros flag, set data array to 0.
- **getLeadingZeros()**
#### Should
- testing other platforms.
- refactor readme.md
- remove degree sign from **displayCelsius()** ?
- remove degree sign from **displayCelsius()**
- would allow one extra digit.
- **displayFahrenheit()** idem.
- could be optional when needed e.g. below -9 or above 99
#### Could
- **keyScan()** camelCase ?
- add parameter for **hideSegement(idx, character == SPACE)** to overrule hide char.
- space underscore or - are possible.
- add **TM1637_UNDERSCORE** to char set. ```seg[19] == 0x08```
- add **TM1637_UPPERSCORE** to char set. ```seg[20] == 0x01```
- return bytes written as return value for display functions.
- like print(); or write();
- **void displayHumidity(int hum, bool colon = false)** print humidity in **percent** format.
The function allows a range from 0.00H .. 99.9H or 00.0H ?
Colon to indicate rising / falling ????
- generic function that displays three digits and one char ACDEFH ???
- common for celsius and fahrenheit and humidity?
- common for Celsius and Fahrenheit and Humidity?
- **void displayAmpere(float amps)** Ampere 0.00 - 999 A
#### Wont (unless requested)
@ -328,8 +405,16 @@ Colon to indicate rising / falling ????
- is now commented code, good enough + dumpcache()
- extend some functions to 6 digit display too?
- time(hh.mm.ss)
- Celsius (nn.nn°C)
- Celsius (nn.nn°C)
- twoInt => threeInt
- on request only
## Support
If you appreciate my libraries, you can support the development and maintenance.
Improve the quality of the libraries by providing issues and Pull Requests, or
donate through PayPal or GitHub sponsors.
Thank you,

View File

@ -2,12 +2,12 @@
// FILE: TM1637.cpp
// AUTHOR: Rob Tillaart
// DATE: 2019-10-28
// VERSION: 0.3.8
// VERSION: 0.3.9
// PURPOSE: TM1637 library for Arduino
// URL: https://github.com/RobTillaart/TM1637_RT
// NOTE:
// on the inexpensive TM1637 boards @wfdudley has used, keyscan
// on the inexpensive TM1637 boards @wfdudley has used, keyScan
// works if you add a 1000 ohm pull-up resistor from DIO to 3.3v
// This reduces the rise time of the DIO signal when reading the key info.
// If one only uses the pull-up inside the microcontroller,
@ -54,7 +54,7 @@
static uint8_t seg[] =
{
0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07, 0x7f, 0x6f, // 0 - 9
0x77, 0x7c, 0x39, 0x5e, 0x79, 0x71, 0x00, 0x40, 0x63 // A - F, ' ', '-', '°'
0x77, 0x7c, 0x39, 0x5e, 0x79, 0x71, 0x00, 0x40, 0x63 // A - F, ' ', '-', '°'
};
@ -99,7 +99,7 @@ void TM1637::begin(uint8_t clockPin, uint8_t dataPin, uint8_t digits)
{
setDigitOrder(3, 2, 1, 0);
}
else // (_digits == 6 ) // default
else // (_digits == 6 ) // default
{
setDigitOrder(3, 4, 5, 0, 1, 2);
}
@ -181,7 +181,7 @@ void TM1637::displayFloat(float value, uint8_t fixedPoint)
last--;
}
// v += 0.0001; // Bug fix for 12.999 <> 13.000
v += 0.001; // Bug fix for 12.99 <> 13.00
v += 0.001; // Bug fix for 12.99 <> 13.00
while (v >= 10)
{
@ -276,7 +276,7 @@ void TM1637::displayCelsius(int temp, bool colon)
if (_digits != 4) return;
for (int i = 0; i < 8; i++) _data[i] = TM1637_SPACE; // 16
_data[0] = 12; // C
_data[1] = TM1637_DEGREE; // ° degreee sign
_data[1] = TM1637_DEGREE; // ° degree sign
if (temp < -9) temp = -9;
if (temp > 99) temp = 99;
@ -299,7 +299,7 @@ void TM1637::displayFahrenheit(int temp, bool colon)
if (_digits != 4) return;
for (int i = 0; i < 8; i++) _data[i] = TM1637_SPACE; // 16
_data[0] = 15; // F
_data[1] = TM1637_DEGREE; // ° degreee sign
_data[1] = TM1637_DEGREE; // ° degree sign
if (temp < -9) temp = -9;
if (temp > 99) temp = 99;
@ -539,15 +539,15 @@ 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():
// 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
// 20 k2 0xef 0xee 0xed 0xec 0xeb 0xea 0xe9 0xe8
uint8_t TM1637::keyscan(void)
uint8_t TM1637::keyScan(void)
{
uint8_t halfDelay = _bitDelay >> 1;
uint8_t key;

View File

@ -3,10 +3,16 @@
// FILE: TM1637.h
// AUTHOR: Rob Tillaart
// DATE: 2019-10-28
// VERSION: 0.3.8
// VERSION: 0.3.9
// PUPROSE: TM1637 library for Arduino
// URL: https://github.com/RobTillaart/TM1637_RT
// NOTE:
// on the inexpensive TM1637 boards @wfdudley has used, keyScan
// works if you add a 1000 ohm pull-up resistor from DIO to 3.3v
// This reduces the rise time of the DIO signal when reading the key info.
// If one only uses the pull-up inside the microcontroller,
// the rise time is too long for the data to be read reliably.
// tested on 6 digit display
// tested on 4 digit (clock) display esp. displayTime()
@ -14,7 +20,7 @@
#include "Arduino.h"
#define TM1637_LIB_VERSION (F("0.3.8"))
#define TM1637_LIB_VERSION (F("0.3.9"))
class TM1637
@ -38,9 +44,9 @@ public:
// next 3 only tested on 4 digit display with colon
void displayTime(uint8_t hh, uint8_t mm, bool colon);
void displayTwoInt(int ll, int rr, bool colon = true);
// Celsius -9..99°C
// Celsius -9..99°C
void displayCelsius(int temp, bool colon = false);
// Fahrenheit -9..99°F
// Fahrenheit -9..99°F
void displayFahrenheit(int temp, bool colon = false);
@ -49,7 +55,7 @@ public:
void displayRefresh();
// EXPERIMENTAL 0.3.8
void hideSegment(uint8_t idx);
void hideMultiSegment(uint8_t mask); // 0 bit = show 1 bit = hide
void hideMultiSegment(uint8_t mask); // 0 bit = show 1 bit = hide
// BRIGHTNESS
@ -65,7 +71,7 @@ public:
// KEY SCAN
uint8_t keyscan(void);
uint8_t keyScan(void);
// CONFIGURATION
@ -77,14 +83,19 @@ public:
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);
// DEBUG only
void dumpCache();
// OBSOLETE
// init() => begin() in 0.4.0
[[deprecated("Use begin() instead")]]
void init(uint8_t clockPin, uint8_t dataPin, uint8_t digits = 6);
// keyscan() => keyScan() in 0.4.0
[[deprecated("Use keyScan() instead => camelCase!")]]
uint8_t keyscan(void) { return keyScan(); };
private:
uint8_t _clockPin = -1;
uint8_t _dataPin = -1;
@ -104,7 +115,7 @@ private:
void writeSync(uint8_t pin, uint8_t val);
void nanoDelay(uint16_t n);
// Override in your own derived class for custom character translation
// Override in your own derived class for custom character translation
virtual uint8_t asciiTo7Segment ( char c ) ;
};

View File

@ -43,7 +43,7 @@ void test()
start = millis();
for (int i = 0; i < 1000; i++)
{
TM.displayHex(val); // there is loop overhead etc
TM.displayHex(val); // there is loop overhead etc
val++;
}
stop = millis();
@ -65,5 +65,5 @@ void test()
}
// -- END OF FILE --
// -- END OF FILE --

View File

@ -36,10 +36,10 @@ void ascii_to_7segment(char *buff, uint8_t *data) {
data[j--] = buff[i] - 'g' + 18;
}
else if(buff[i] == '.') {
data[j+1] |= 0x80; // decimal point on previous digit
data[j+1] |= 0x80; // decimal point on previous digit
}
else {
data[j--] = 0x10; // blank
data[j--] = 0x10; // blank
}
}
}
@ -59,5 +59,5 @@ uint8_t data[10];
}
// -- END OF FILE --
// -- END OF FILE --

View File

@ -49,9 +49,9 @@ void setup()
// left as exercise for the programmer ;)
void loop()
{
uint32_t now = millis() % 100000; // 0 - 99999
float value = now * 0.001; // 0 - 99.999
if (value - int(value) < 0.5) value *= 100; // for blink :
uint32_t now = millis() % 100000; // 0 - 99999
float value = now * 0.001; // 0 - 99.999
if (value - int(value) < 0.5) value *= 100; // for blink :
TM.displayFloat(value);
}
@ -65,5 +65,5 @@ void loop2()
}
// -- END OF FILE --
// -- END OF FILE --

View File

@ -7,7 +7,7 @@
// URL: https://github.com/radionerd
// Demonstration of how to display char *buff and override the TM1637 library asciiTo7Segment virtual function
// to create a custom 7 segment character set.
// to create a custom 7 segment character set.
// The letter 'A' becomes swapped with @ in this trivial example
// Status: Experimental. Tested on STM32F103C8T6 Blue Pill and Arduino Nano only
@ -23,15 +23,15 @@ const int DISPLAY_DIGITS_6 = 6;
class myTM1637 : TM1637 {
public:
void setBrightness(uint8_t b) { TM1637::setBrightness(b);};
void begin(uint8_t clockPin, uint8_t dataPin, uint8_t digits = 6) {TM1637::begin(clockPin,dataPin,digits);};
void displayPChar( char * data ) {
TM1637::displayPChar( &data[0] ); // Call the base class
Serial.println(data); // Copy display output to the serial port
void displayPChar( char * data ) {
TM1637::displayPChar( &data[0] ); // Call the base class
Serial.println(data); // Copy display output to the serial port
};
uint8_t asciiTo7Segment ( char c ) { // Override library ascii to 7 segment conversion
uint8_t asciiTo7Segment ( char c ) { // Override library ascii to 7 segment conversion
// -01-
// 20 | | 02
@ -40,15 +40,15 @@ class myTM1637 : TM1637 {
// -08- .80
//7+1 Segment patterns for ASCII 0x30-0x5F
const uint8_t asciiTo8Segment[] = {
0x00,0x86,0x22,0x7f, 0x6d,0x52,0x7d,0x02, // !"# $%&'
0x39,0x0f,0x7f,0x46, 0x80,0x40,0x80,0x52, // ()*+ ,-./
0x3f,0x06,0x5b,0x4f, 0x66,0x6d,0x7d,0x07, // 0123 4567
0x7f,0x6f,0x09,0x89, 0x58,0x48,0x4c,0xD3, // 89:; <=>?
0x77,0x5f,0x7c,0x39, 0x5E,0x79,0x71,0x3d, // @aBC DEFG NB: @ <-> A in this derived class
0x74,0x06,0x0E,0x75, 0x38,0x37,0x54,0x5c, // HIJK LMNO
0x73,0x67,0x50,0x6D, 0x78,0x3E,0x1C,0x9c, // PQRS TUVW
0x76,0x6E,0x5B,0x39, 0x52,0x0F,0x23,0x08 // XYZ[ /]^_
const uint8_t asciiTo8Segment[] = {
0x00,0x86,0x22,0x7f, 0x6d,0x52,0x7d,0x02, // !"# $%&'
0x39,0x0f,0x7f,0x46, 0x80,0x40,0x80,0x52, // ()*+ ,-./
0x3f,0x06,0x5b,0x4f, 0x66,0x6d,0x7d,0x07, // 0123 4567
0x7f,0x6f,0x09,0x89, 0x58,0x48,0x4c,0xD3, // 89:; <=>?
0x77,0x5f,0x7c,0x39, 0x5E,0x79,0x71,0x3d, // @aBC DEFG NB: @ <-> A in this derived class
0x74,0x06,0x0E,0x75, 0x38,0x37,0x54,0x5c, // HIJK LMNO
0x73,0x67,0x50,0x6D, 0x78,0x3E,0x1C,0x9c, // PQRS TUVW
0x76,0x6E,0x5B,0x39, 0x52,0x0F,0x23,0x08 // XYZ[ /]^_
};
uint8_t segments = c &0x80;
@ -69,12 +69,12 @@ void setup()
delay(1000);
Serial.println(__FILE__);
// set clockpin, datapin to your own board pin names
// e.g. myTM.begin(PB8, PB9 , DISPLAY_DIGITS_6 );
myTM.begin( 14, 15 , DISPLAY_DIGITS_6 ); // clockpin, datapin, and digits
// set clockpin, datapin to your own board pin names
// e.g. myTM.begin(PB8, PB9 , DISPLAY_DIGITS_6 );
myTM.begin( 14, 15 , DISPLAY_DIGITS_6 ); // clockpin, datapin, and digits
myTM.setBrightness(2);
}
@ -82,12 +82,12 @@ void loop()
{
char buff[20];
static int seconds;
// Show A and @ swapped over on custom character set
// Compare the 7 segment display with the text shown on the serial monitor
// Show A and @ swapped over on custom character set
// Compare the 7 segment display with the text shown on the serial monitor
sprintf(buff,"@-A%3d", seconds++%100 );
myTM.displayPChar(buff); // send buffer to display and serial port
myTM.displayPChar(buff); // send buffer to display and serial port
delay(1000);
}
// -- END OF FILE --
// -- END OF FILE --

View File

@ -36,4 +36,4 @@ void loop()
}
// -- END OF FILE --
// -- END OF FILE --

View File

@ -43,4 +43,4 @@ void loop()
}
// -- END OF FILE --
// -- END OF FILE --

View File

@ -24,11 +24,11 @@ void setup()
TM.displayFloat(1.42425);
// TM.dumpCache();
delay(2000);
TM.displayFloat(-1.42425);
// TM.dumpCache();
delay(2000);
TM.displayClear();
// TM.dumpCache();
delay(2000);
@ -47,7 +47,7 @@ void test()
start = millis();
for (int i = 0; i < 1000; i++)
{
TM.displayFloat(f); // there is loop overhead etc
TM.displayFloat(f); // there is loop overhead etc
f += 1;
}
stop = millis();
@ -57,5 +57,5 @@ void test()
}
// -- END OF FILE --
// -- END OF FILE --

View File

@ -57,4 +57,4 @@ void loop()
}
// -- END OF FILE --
// -- END OF FILE --

View File

@ -55,5 +55,5 @@ void test()
}
// -- END OF FILE --
// -- END OF FILE --

View File

@ -2,7 +2,7 @@
// FILE: TM1637_keypress_cooked.ino
// AUTHOR: William F. Dudley Jr.
// VERSION: 0.1.0
// PURPOSE: demo TM1637 library - keyscan() cooked output
// PURPOSE: demo TM1637 library - keyScan() cooked output
// DATE: 2021-10-26
// URL: https://github.com/RobTillaart/TM1637
@ -12,9 +12,9 @@
TM1637 TM;
// Note: In my experience, the TM1637 boards need a pull up
// resistor from DIO to 3.3V for keyscan() to work. 1000 ohms
// seems to work well, but value isn't critical.
// Note: In my experience, the TM1637 boards need a pull up
// resistor from DIO to 3.3V for keyScan() to work. 1000 ohms
// seems to work well, but value isn't critical.
char buff[8];
@ -49,10 +49,11 @@ void setup()
char button_poll(void) {
char c;
static unsigned long last_key_time;
uint8_t keypress = TM.keyscan();
uint8_t keypress = TM.keyScan();
c = '\0';
// TM.displayHex(keypress); // uncomment to see raw data on LED
// Serial.print("kp "); Serial.println(keypress, HEX); // uncomment to see raw
// TM.displayHex(keypress); // uncomment to see raw data on LED
// Serial.print("kp "); // uncomment to see raw
// Serial.println(keypress, HEX); // uncomment to see raw
if(keypress < 0xfe) {
if(last_keypress != keypress || (millis() - last_key_time) > 500) {
last_keypress = keypress;
@ -97,10 +98,10 @@ void ascii_to_7segment(char *buff, uint8_t *data) {
data[j--] = buff[i] - 'g' + 18;
}
else if(buff[i] == '.') {
data[j+1] |= 0x80; // decimal point on previous digit
data[j+1] |= 0x80; // decimal point on previous digit
}
else {
data[j--] = 0x10; // blank
data[j--] = 0x10; // blank
}
}
}
@ -115,7 +116,7 @@ char c;
buff[bptr++] = c;
if(bptr > 5) { bptr = 0; }
Serial.println(buff);
// convert ASCII chars in "buff" to 7 segment representations in "data"
// convert ASCII chars in "buff" to 7 segment representations in "data"
ascii_to_7segment(buff, data);
TM.displayRaw(data, -1);
}
@ -123,5 +124,5 @@ char c;
}
// -- END OF FILE --
// -- END OF FILE --

View File

@ -2,7 +2,7 @@
// FILE: TM1637_keypress_raw.ino
// AUTHOR: William F. Dudley Jr.
// VERSION: 0.1.0
// PURPOSE: demo TM1637 library - keyscan() raw output
// PURPOSE: demo TM1637 library - keyScan() raw output
// DATE: 2021-10-26
// URL: https://github.com/RobTillaart/TM1637
@ -11,18 +11,18 @@
TM1637 TM;
// Note: In my experience, the TM1637 boards need a pull up
// resistor from DIO to 3.3V for keyscan() to work. 1000 ohms
// seems to work well, but value isn't critical.
// Note: In my experience, the TM1637 boards need a pull up
// resistor from DIO to 3.3V for keyScan() to work. 1000 ohms
// seems to work well, but value isn't critical.
// TRIGGER is scope trigger signal for development.
// Comment out the #define if you don't need it.
// or feel free to change to any unused pin. Hook your
// oscilloscope or logic analyzer trigger to it.
// This allows experimenting with the pullup resistor
// from DIO to 3.3V. Smaller values decrease rise time
// (a good thing) but too small and the microcontroller
// can't pull the line down (a bad thing). Try 1000 ohms.
// TRIGGER is scope trigger signal for development.
// Comment out the #define if you don't need it.
// or feel free to change to any unused pin. Hook your
// oscilloscope or logic analyzer trigger to it.
// This allows experimenting with the pullup resistor
// from DIO to 3.3V. Smaller values decrease rise time
// (a good thing) but too small and the microcontroller
// can't pull the line down (a bad thing). Try 1000 ohms.
#define dispCLOCK 3
@ -57,7 +57,7 @@ char button_poll(void) {
delayMicroseconds(1);
digitalWrite(TRIGGER, LOW);
#endif
uint8_t keypress = TM.keyscan();
uint8_t keypress = TM.keyScan();
TM.displayHex(keypress);
if(keypress < 0xfe) {
Serial.print(F("KEYPRESS "));
@ -72,11 +72,11 @@ void loop()
button_poll();
#ifndef TRIGGER
// for oscilloscope testing, don't delay for faster repetition rate
// for oscilloscope testing, don't delay for faster repetition rate
delay(50);
#endif
}
// -- END OF FILE --
// -- END OF FILE --

View File

@ -21,9 +21,9 @@ void setup()
delay(1000);
Serial.println(__FILE__);
// set clockpin, datapin to your own board pin names
// e.g. myTM.begin(PB8, PB9 , DISPLAY_DIGITS_6 );
TM.begin( 14, 15 , DISPLAY_DIGITS_6 ); // clockpin, datapin, and digits
// set clockpin, datapin to your own board pin names
// e.g. myTM.begin(PB8, PB9 , DISPLAY_DIGITS_6 );
TM.begin( 14, 15 , DISPLAY_DIGITS_6 ); // clockpin, datapin, and digits
TM.setBrightness(2);
@ -35,10 +35,10 @@ void loop()
char buff[20];
static int seconds;
sprintf(buff,"Sec=%02x", seconds++&0xFF );
TM.displayPChar(buff); // send buffer to display
Serial.println(buff); // and serial port.
TM.displayPChar(buff); // send buffer to display
Serial.println(buff); // and serial port.
delay(1000);
}
// -- END OF FILE --
// -- END OF FILE --

View File

@ -25,13 +25,19 @@ displayTwoInt KEYWORD2
displayCelsius KEYWORD2
displayFahrenheit KEYWORD2
displayClear KEYWORD2
displayRefresh KEYWORD2
hideSegment KEYWORD2
hideMultiSegment KEYWORD2
setBrightness KEYWORD2
getBrightness KEYWORD2
setBitDelay KEYWORD2
getBitDelay KEYWORD2
keyscan KEYWORD2
keyScan KEYWORD2
setDigitOrder KEYWORD2

View File

@ -15,9 +15,9 @@
"type": "git",
"url": "https://github.com/RobTillaart/TM1637_RT"
},
"version": "0.3.8",
"version": "0.3.9",
"license": "MIT",
"frameworks": "arduino",
"frameworks": "*",
"platforms": "*",
"headers": "TM1637.h"
}

View File

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