0.3.4 TM1637_RT

This commit is contained in:
rob tillaart 2022-10-07 11:32:52 +02:00
parent c7cc4b04fa
commit 50cd6a5fdb
10 changed files with 239 additions and 96 deletions

View File

@ -1,3 +1,18 @@
platforms:
rpipico:
board: rp2040:rp2040:rpipico
package: rp2040:rp2040
gcc:
features:
defines:
- ARDUINO_ARCH_RP2040
warnings:
flags:
packages:
rp2040:rp2040:
url: https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json
compile:
# Choosing to run compilation tests on 2 different Arduino platforms
platforms:
@ -8,4 +23,5 @@ compile:
- m4
- esp32
# - esp8266
# - mega2560
# - mega2560
- rpipico

View File

@ -5,6 +5,13 @@ 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
- 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

View File

@ -24,6 +24,7 @@ ESP32 is supported since 0.2.0 see https://github.com/RobTillaart/TM1637_RT/pull
- **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 displayRaw(uint8_t \* data, uint8_t pointPos)** low level write function.
- **void displayInt(long value)** idem
- **void displayFloat(float value)** idem
@ -34,17 +35,23 @@ As the display is only tested with a 6 digit display, this is used as the defaul
- **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) 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.
**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.
**displayRaw()** can display some of the alphabet as follows:
- space (blank) is 0x10
- '-' (minus) is 0x11
- 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
**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.
See routine **ascii_to_7segment()** in the example TM1637_keyscan_cooked.ino. It presents a more convenient interface for displaying text messages on the display.
See routine **ascii_to_7segment()** in the example TM1637_keyscan_cooked.ino.
It presents a more convenient interface for displaying text messages on the display.
Routine **button_poll()** in the same example shows one way of polling and de-bouncing button presses.
@ -159,12 +166,13 @@ See examples
### 0.4.0
- remove obsolete **init()** from code
- investigate if code can be optimized
- performance measurement
### other
- testing platforms.
- investigate if code can be optimized
- performance measurement
- testing other platforms.
- **keyScan()** camelCase ?

View File

@ -2,7 +2,7 @@
// FILE: TM1637.cpp
// AUTHOR: Rob Tillaart
// DATE: 2019-10-28
// VERSION: 0.3.3
// VERSION: 0.3.4
// PURPOSE: TM1637 library for Arduino
// URL: https://github.com/RobTillaart/TM1637_RT
@ -202,6 +202,29 @@ void TM1637::setDigitOrder(uint8_t a, uint8_t b,
}
// Set sign bit on any char to display decimal point
void TM1637::displayPChar( char * data )
{
start();
writeByte(TM1637_ADDR_AUTO);
stop();
start();
writeByte(TM1637_CMD_SET_ADDR);
for (int d = _digits-1; d >=0 ; d--)
{
uint8_t i = _digitOrder[d];
writeByte( asciiTo7Segment(data[i]) );
}
stop();
start();
writeByte(TM1637_CMD_DISPLAY | _brightness);
stop();
}
void TM1637::displayRaw(uint8_t * data, uint8_t pointPos)
{
uint8_t b = 0;
@ -240,89 +263,6 @@ void TM1637::displayRaw(uint8_t * data, uint8_t pointPos)
}
/* previous version
void TM1637::displayRaw(uint8_t * data, uint8_t pointPos)
{
uint8_t b = 0, dp = 0;
start();
writeByte(TM1637_ADDR_AUTO);
stop();
// for debugging new displays...
// for (int i = 0; i< 6; i++)
// {
// Serial.print(data[i]);
// Serial.print("\t");
// }
// Serial.println();
start();
writeByte(TM1637_CMD_SET_ADDR);
// TODO: how to encode display digit order in a generic way?
// 2nd array? (packed in nybbles?)
// 6 digits == 2x3 display
// [3,4,5,0,1,2]
if (_digits == 6)
{
for (uint8_t i = 3; i < 6 ; i++)
{
dp = data[i] & 0x80;
data[i] &= 0x7f;
if(data[i] <= 17) {
b = seg[data[i]];
}
else if(data[i] <= 37) {
b = alpha_seg[data[i]-18];
}
if (i == pointPos || dp) b |= 0x80;
writeByte(b);
}
for (uint8_t i = 0; i < 3 ; i++)
{
dp = data[i] & 0x80;
data[i] &= 0x7f;
if(data[i] <= 17) {
b = seg[data[i]];
}
else if(data[i] <= 37) {
b = alpha_seg[data[i]-18];
}
if (i == pointPos || dp) b |= 0x80;
writeByte(b);
}
}
// 4 digit clock version. => : is the point at digit 2
// [3,2,1,0]
if (_digits == 4)
{
for (uint8_t j = 0; j < 4 ; j++)
{
uint8_t i = 3 - j;
dp = data[i] & 0x80; // repeating block till writeByte()
data[i] &= 0x7f;
if(data[i] <= 17) {
b = seg[data[i]];
}
else if(data[i] <= 37) {
b = alpha_seg[data[i]-18];
}
if (i == pointPos || dp) b |= 0x80;
writeByte(b);
}
}
stop();
start();
writeByte(TM1637_CMD_DISPLAY | _brightness);
stop();
}
*/
//////////////////////////////////////////////////////
//
// PRIVATE
@ -434,5 +374,36 @@ void TM1637::nanoDelay(uint16_t n)
}
uint8_t TM1637::asciiTo7Segment ( char c )
{
/*
-01-
20 | | 02
-40-
10 | | 04
-08- .80
*/
// 7+1 Segment patterns for ASCII 0x30-0x5F
const uint8_t asciiToSegments[] = {
0x3f,0x06,0x5b,0x4f, 0x66,0x6d,0x7d,0x07, // 0123 4567
0x7f,0x6f,0x09,0x89, 0x58,0x48,0x4c,0xD3, // 89:; <=>?
0x5f,0x77,0x7c,0x39, 0x5E,0x79,0x71,0x3d, // @ABC DEFG
0x76,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;
c &= 0x7f;
if ( c >= 0x60 ) c -= 0x20 ; // a-z -> A-Z
if ( c == '.' ) segments = 0x80; // decimal point only
if ( c == '-' ) segments |= 0x40; // minus sign
if ( ( c >= 0x30 ) && ( c <= 0x5F ) ) {
segments |= asciiToSegments[ c - 0x30 ];
}
return segments;
}
// -- END OF FILE --

View File

@ -3,7 +3,7 @@
// FILE: TM1637.h
// AUTHOR: Rob Tillaart
// DATE: 2019-10-28
// VERSION: 0.3.3
// VERSION: 0.3.4
// 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.3"))
#define TM1637_LIB_VERSION (F("0.3.4"))
class TM1637
@ -24,6 +24,7 @@ public:
// replaces init()
void begin(uint8_t clockPin, uint8_t dataPin, uint8_t digits = 6);
void displayPChar( char * buff );
void displayRaw(uint8_t * data, uint8_t pointPos);
void displayInt(long value);
void displayFloat(float value);
@ -64,6 +65,9 @@ private:
void writeSync(uint8_t pin, uint8_t val);
void nanoDelay(uint16_t n);
// Override in your own derived class for custom character translation
virtual uint8_t asciiTo7Segment ( char c ) ;
};

View File

@ -0,0 +1,93 @@
//
// FILE: TM1637_custom.ino
// AUTHOR: Richard Jones
// VERSION: 0.1.0
// PURPOSE: demo TM1637 library
// DATE: 3 October 2022
// 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.
// The letter 'A' becomes swapped with @ in this trivial example
// Status: Experimental. Tested on STM32F103C8T6 Blue Pill and Arduino Nano only
#include "TM1637.h"
const int DISPLAY_DIGITS_6 = 6;
// This example shows how to override the TM1637_RT library 7 segment patterns and copy the display output
// to the serial port overriding and adding to the library methods.
// myTM1637 inherits from library class TM1637 and overrides the library asciiTo7Segment() method.
// The derived class displayPChar() method also copies the display output to the serial port.
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
};
uint8_t asciiTo7Segment ( char c ) { // Override library ascii to 7 segment conversion
// -01-
// 20 | | 02
// -40-
// 10 | | 04
// -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[ /]^_
};
uint8_t segments = c &0x80;
c &= 0x7f;
if ( c >= 0x60 ) c -= 0x20 ; // a-z -> A-Z
if ( ( c >= 0x20 ) && ( c <= 0x5F ) ) {
segments |= asciiTo8Segment[c-0x20];
}
return segments;
}
};
myTM1637 myTM;
void setup()
{
Serial.begin(115200);
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
myTM.setBrightness(2);
}
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
sprintf(buff,"@-A%3d", seconds++%100 );
myTM.displayPChar(buff); // send buffer to display and serial port
delay(1000);
}
// -- END OF FILE --

View File

@ -0,0 +1,44 @@
//
// FILE: TM1637_pchar.ino
// AUTHOR: Richard Jones
// VERSION: 0.1.0
// PURPOSE: demo TM1637 library
// DATE: 4 October 2022
// URL: https://github.com/radionerd
// Demonstration of how to display char *buff
// Status: Experimental. Tested on STM32F103C8T6 Blue Pill and Arduino Nano only
#include "TM1637.h"
const int DISPLAY_DIGITS_6 = 6;
TM1637 TM;
void setup()
{
Serial.begin(115200);
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
TM.setBrightness(2);
}
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.
delay(1000);
}
// -- END OF FILE --

View File

@ -8,7 +8,7 @@ TM1637 KEYWORD1
# Methods and Functions (KEYWORD2)
begin KEYWORD2
displayPChar KEYWORD2
displayRaw KEYWORD2
displayInt KEYWORD2
displayFloat KEYWORD2

View File

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

View File

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