0.4.0 HT16K33

This commit is contained in:
Rob Tillaart 2023-12-05 20:32:12 +01:00
parent 7692ae8cb8
commit 581e65e705
22 changed files with 180 additions and 112 deletions

View File

@ -6,11 +6,22 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).
## [0.4.0] - 2023-12-05
- refactor API, begin()
- update readme.md
- remove obsolete getAddr() => **getAddress()**
- rename brightness() => **setBrightness()**
- add **getBrightness()**
- rename blink() ==> **setBlink()**
- add **getBlink()**
- minor edits
----
## [0.3.9] - 2023-09-22
- add Wire1 support for ESP32
- update readme.md
## [0.3.8] - 2023-02-26
- add **getBrightness()**
- moved code to .cpp file (prep 0.4.0)
@ -20,7 +31,6 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- update license 2023
- minor edits
## [0.3.7] - 2022-11-19
- add displayUnit(float, char);
- add top c symbol

View File

@ -1,7 +1,7 @@
//
// FILE: HT16K33.cpp
// AUTHOR: Rob Tillaart
// VERSION: 0.3.9
// VERSION: 0.4.0
// DATE: 2019-02-07
// PURPOSE: Arduino Library for HT16K33 4x7segment display
// URL: https://github.com/RobTillaart/HT16K33
@ -76,25 +76,8 @@ HT16K33::HT16K33(const uint8_t address, TwoWire *wire)
}
#if defined (ESP8266) || defined(ESP32)
bool HT16K33::begin(uint8_t sda, uint8_t scl)
{
if ((sda < 255) && (scl < 255))
{
_wire->begin(sda, scl);
} else {
_wire->begin();
}
if (! isConnected()) return false;
reset();
return true;
}
#endif
bool HT16K33::begin()
{
_wire->begin();
if (! isConnected()) return false;
reset();
return true;
@ -113,7 +96,8 @@ void HT16K33::reset()
displayClear();
setDigits(1);
clearCache();
brightness(8);
setBrightness(8);
setBlink(0);
}
@ -136,7 +120,6 @@ void HT16K33::cacheOn()
}
void HT16K33::cacheOff()
{
_cache = false;
@ -157,7 +140,7 @@ void HT16K33::displayOn()
{
writeCmd(HT16K33_ON);
writeCmd(HT16K33_DISPLAYON);
brightness(_bright);
setBrightness(_bright);
}
@ -168,14 +151,21 @@ void HT16K33::displayOff()
}
void HT16K33::blink(uint8_t value)
void HT16K33::setBlink(uint8_t value)
{
if (value > 0x03) value = 0x00;
_blink = value;
writeCmd(HT16K33_BLINKOFF | (value << 1) );
}
void HT16K33::brightness(uint8_t value)
uint8_t HT16K33::getBlink()
{
return _blink;
}
void HT16K33::setBrightness(uint8_t value)
{
if (value == _bright) return;
_bright = value;
@ -196,6 +186,12 @@ void HT16K33::setDigits(uint8_t value)
}
uint8_t HT16K33::getDigits()
{
return _digits;
}
void HT16K33::suppressLeadingZeroPlaces(uint8_t value)
{
_digits = value > 4 ? 0 : 4 - value;
@ -433,6 +429,7 @@ bool HT16K33::displayFixedPoint0(float f)
return inRange;
}
bool HT16K33::displayFixedPoint1(float f)
{
bool inRange = ((-99.5 < f) && (f < 999.95));
@ -440,6 +437,7 @@ bool HT16K33::displayFixedPoint1(float f)
return inRange;
}
bool HT16K33::displayFixedPoint2(float f)
{
bool inRange = ((-9.95 < f) && (f < 99.995));
@ -447,6 +445,7 @@ bool HT16K33::displayFixedPoint2(float f)
return inRange;
}
bool HT16K33::displayFixedPoint3(float f)
{
bool inRange = ((0 < f) && (f < 9.9995));
@ -454,6 +453,7 @@ bool HT16K33::displayFixedPoint3(float f)
return inRange;
}
/////////////////////////////////////////////////////////////////////
void HT16K33::displayTest(uint8_t del)
@ -608,11 +608,6 @@ uint8_t HT16K33::getAddress()
//////////////////////////////////////////////////////////
//
// PRIVATE
@ -628,6 +623,7 @@ void HT16K33::_refresh()
}
}
void HT16K33::writeCmd(uint8_t cmd)
{
_wire->beginTransmission(_address);

View File

@ -2,7 +2,7 @@
//
// FILE: HT16K33.h
// AUTHOR: Rob Tillaart
// VERSION: 0.3.9
// VERSION: 0.4.0
// DATE: 2019-02-07
// PURPOSE: Arduino Library for HT16K33 4x7segment display
// http://www.adafruit.com/products/1002
@ -13,7 +13,7 @@
#include "Wire.h"
#define HT16K33_LIB_VERSION (F("0.3.9"))
#define HT16K33_LIB_VERSION (F("0.4.0"))
// Characters
@ -45,12 +45,8 @@ class HT16K33
public:
HT16K33(const uint8_t address, TwoWire *wire = &Wire); // 0x70 .. 0x77
#if defined (ESP8266) || defined(ESP32)
bool begin(uint8_t sda, uint8_t scl);
#endif
bool begin();
void reset();
bool isConnected();
// default _cache is true as it is ~3x faster but if one has noise
@ -64,13 +60,16 @@ public:
void displayOn();
void displayOff();
void brightness(uint8_t value); // 0 .. 15
void setBrightness(uint8_t value); // 0 .. 15
uint8_t getBrightness();
void blink(uint8_t value); // 0 .. 3 0 = off
void setBlink(uint8_t value); // 0 .. 3 0 = off
uint8_t getBlink();
// 0,1,2,3,4 digits - will replace suppressLeadingZeroPlaces
void setDigits(uint8_t value);
uint8_t getDigits();
void displayClear();
bool displayInt(int n); // -999 .. 9999
@ -122,14 +121,14 @@ public:
bool displayFixedPoint2(float f);
bool displayFixedPoint3(float f);
// OBSOLETE SOON
// use getAddress(); instead.
uint8_t getAddr() { return getAddress(); };
// use setDigits(); instead.
// 0 = off, 1,2,3,4 digits space instead of 0
void suppressLeadingZeroPlaces(uint8_t value);
void suppressLeadingZeroPlaces(uint8_t value);
// OBSOLETE 0.4.x
void brightness(uint8_t value) { setBrightness(value); };
void blink(uint8_t value) { setBlink(value); };
private:
@ -143,6 +142,7 @@ private:
bool _cache = true;
uint8_t _digits = 0;
uint8_t _bright;
uint8_t _blink;
TwoWire* _wire;
};

View File

@ -25,6 +25,15 @@ it is faster for writing on average. The actual gain depends on the
application and of course the values.
#### 0.4.0 Breaking change
Version 0.4.0 introduced a breaking change.
You cannot set the pins in **begin()** any more.
This reduces the dependency of processor dependent Wire implementations.
The user has to call **Wire.begin()** and can optionally set the Wire pins
before calling **begin()**.
## Perfomance
Version 0.3.0 allows one to switch the caching on/off to enforce
@ -66,13 +75,12 @@ get leading/trailing zero's correctly.
#### Setup behaviour
- **HT16K33(const uint8_t address)** address is 0x70..0x77 depending on the jumpers A0..A2. **0x70** is default.
- **bool begin(uint8_t sda, uint8_t scl)** for ESP32, select I2C pins, initialize I2C and calls **reset()**.
Returns false if device not seen on I2C bus.
- **bool begin()** initialize I2C and calls **reset()**.
Returns false if device not seen on I2C bus.
- **bool isConnected()** Returns false if device not seen on I2C bus.
- **bool begin()** initialize library and calls **reset()**.
Returns false if address not seen on I2C bus.
- **bool isConnected()** Returns false if address not seen on I2C bus.
- **void reset()** resets display.
#### Cache
- **void clearCache()** forced clearing of the cache, to be used to switch the cache off just for one write.
@ -83,10 +91,12 @@ Returns false if device not seen on I2C bus.
- **void displayOn()** enable display.
- **void displayOff()** disable display, fast way to darken display e.g. for energy consumption.
- **void brightness(uint8_t value)** values (dim) 0..15 (bright).
- **void blink(uint8_t value)** values 0..3 0 = off.
- **void setBrightness(uint8_t value)** values (dim) 0..15 (bright).
- **void getBrightness()** returns (dim) 0..15 (bright).
- **void setBlink(uint8_t value)** values 0..3 0 = off.
- **void getBlink(uint8_t value)** values 0..3 0 = off.
- **void setDigits(uint8_t value)** values 0..4, minimal number of digits shown, mandatory for large numbers on dual display.
- **uint8_t getAddress()** idem.
#### Data types
@ -115,9 +125,7 @@ The unitChar must be one of the chars supported like HT16K33_C, HT16K33_TOP_C or
So **displayUnit(25.6, 1, HT16K33_DEGREE)** will display **23.5°**.
#### Experimental fixed point
These functions are new and still under investigation.
#### Fixed point
- **bool displayFixedPoint0(float f)** displays values -999 .. 9999 without decimals.
- **bool displayFixedPoint1(float f)** displays values -99.9 .. 999.9 with 1 decimals.
@ -137,7 +145,7 @@ These functions are new and still under investigation.
- **void display(uint8_t \* array, uint8_t point)** idem + point = position of the digit with point (0..3).
- **void displayColon(uint8_t on)** 0 = off, all values other are on.
- **void displayRaw(uint8_t \* array, bool colon)** array of 4 bytes to control one 7seg display + colon flag.
- **void displayExtraLeds(uint8_t value)** switch on extra leds.
- **void displayExtraLeds(uint8_t value)** switch on extra LEDs.
value is in fact a bit mask see table below. 0 = all off.
@ -160,12 +168,13 @@ value is in fact a bit mask see table below. 0 = all off.
- **void dumpSerial(uint8_t \* array, uint8_t point)** debugging equivalent of the display.
Prints to Serial.
- **void dumpSerial()** print HEX codes equivalent of the display to Serial.
- **uint8_t getAddress()** idem.
#### Obsolete
#### Obsolete soon
- suppressLeadingZeroPlaces(uint8_t value) use **setDigits()**
- getAddr() use **getAddress()**
- brightness() use setBrightness()
- blink() use setBlink()
## Characters supported
@ -209,18 +218,13 @@ See examples
#### Must
Mainly for a 0.4.0
Mainly for a 0.4.x
- **bool isDisplayOn()** and similar state functions
- configuration byte: 4 bits brightness, 1 bit on off flag, 1 bit cache flag, 2 blink rate
#### Should
- **void setBrightness()**
- **void setBlink()** and **uint8_t getBlink()**
- **void getDigits()**
- **FixedPoint()** regular (experimental in 0.3.2)
#### Could
@ -233,7 +237,6 @@ Mainly for a 0.4.0
- [status] dd.d
- add examples
- car battery monitor (voltage divider & analogRead)
-
- add more "special chars"?
- #define HT16K33_P Pascal / Pressure 0x73
- #define HT16K33_J joule 0x0E

View File

@ -17,9 +17,12 @@ void setup()
{
Serial.begin(115200);
Serial.println(__FILE__);
Serial.print("HT16K33_LIB_VERSION: ");
Serial.println(HT16K33_LIB_VERSION);
seg.begin();
Wire.begin();
Wire.setClock(100000);
seg.begin();
seg.displayOn();
Serial.println("displayTest()");
@ -44,17 +47,17 @@ void loop()
for (int i = 0; i < 16; i++)
{
seg.displayHex(0xABC0 + i);
seg.brightness(i);
seg.setBrightness(i);
delay(500);
}
for (int i = 15; i >= 0; i--)
{
seg.displayHex(0xABC0 + i);
seg.brightness(i);
seg.setBrightness(i);
delay(500);
}
delay(1000);
seg.brightness(2);
seg.setBrightness(2);
Serial.println("displayClear()");
seg.displayClear();
@ -123,14 +126,14 @@ void loop()
delay(100);
}
Serial.println("blink()");
Serial.println("setBlink()");
for (uint8_t i = 0; i < 3; i++)
{
seg.displayHex(0xABC0 + i);
seg.blink(i);
seg.setBlink(i);
delay(4000);
}
seg.blink(0);
seg.setBlink(0);
Serial.print("INT TEST:\t");
start = millis();
@ -174,5 +177,5 @@ void loop()
}
// -- END OF FILE --
// -- END OF FILE --

View File

@ -5,6 +5,7 @@
// URL: http://www.adafruit.com/products/1002
// URL: https://github.com/RobTillaart/HT16K33
#include "HT16K33.h"
HT16K33 seg(0x70);
@ -12,17 +13,21 @@ HT16K33 seg(0x70);
uint32_t start;
uint32_t stop;
void setup()
{
Serial.begin(115200);
Serial.println(__FILE__);
Serial.print("HT16K33_LIB_VERSION: ");
Serial.println(HT16K33_LIB_VERSION);
seg.begin();
Wire.begin();
Wire.setClock(100000);
seg.begin();
seg.displayOn();
seg.suppressLeadingZeroPlaces(0);
Serial.println("displayTest()");
seg.displayTest(100);
seg.displayOff();
@ -43,15 +48,15 @@ void loop()
Serial.println("dim()");
for (int i = 0; i < 16; i++)
{
seg.brightness(i);
seg.setBrightness(i);
delay(500);
}
for (int i = 15; i > 0; i--)
{
seg.brightness(i);
seg.setBrightness(i);
delay(500);
}
seg.brightness(2);
seg.setBrightness(2);
Serial.println("displayClear()");
seg.displayClear();
@ -100,13 +105,13 @@ void loop()
delay(100);
}
Serial.println("blink()");
Serial.println("setBlink()");
for (uint8_t i = 0; i < 3; i++)
{
seg.blink(i);
seg.setBlink(i);
delay(4000);
}
seg.blink(0);
seg.setBlink(0);
Serial.print("INT TEST:\t");
start = millis();
@ -140,4 +145,4 @@ void loop()
}
// -- END OF FILE --
// -- END OF FILE --

View File

@ -5,6 +5,7 @@
// URL: http://www.adafruit.com/products/1002
// URL: https://github.com/RobTillaart/HT16K33
#include "HT16K33.h"
HT16K33 seg(0x70);
@ -14,13 +15,17 @@ uint32_t stop;
uint8_t ar[4];
void setup()
{
Serial.begin(115200);
Serial.println(__FILE__);
Serial.print("HT16K33_LIB_VERSION: ");
Serial.println(HT16K33_LIB_VERSION);
seg.begin();
Wire.begin();
Wire.setClock(100000);
seg.begin();
seg.displayOn();
seg.suppressLeadingZeroPlaces(0);
@ -35,7 +40,7 @@ void setup()
void loop()
{
// comment tests you do not want to see
// comment tests you do not want to see
test_elsa();
delay(100);
test_random();
@ -69,7 +74,7 @@ void test_random()
void test_VULeft()
{
int val = analogRead(A0);
val = val / 120; // 0..8
val = val / 120; // 0..8
seg.displayVULeft(val);
}
@ -82,8 +87,8 @@ void test_VURight()
void test_VUStereo()
{
uint8_t left = analogRead(A0) / 240; // 0..4
uint8_t right = analogRead(A1) / 240; // 0..4
uint8_t left = analogRead(A0) / 240; // 0..4
uint8_t right = analogRead(A1) / 240; // 0..4
displayVUStereo(left, right);
}
@ -139,10 +144,10 @@ void displayVUStereo(uint8_t left, uint8_t right)
}
seg.displayRaw(ar);
// sort of heartbeat
// sort of heartbeat
static bool t = false;
seg.displayColon(t);
t = !t;
}
// -- END OF FILE --
// -- END OF FILE --

View File

@ -19,9 +19,12 @@ void setup()
{
Serial.begin(115200);
Serial.println(__FILE__);
Serial.print("HT16K33_LIB_VERSION: ");
Serial.println(HT16K33_LIB_VERSION);
seg.begin();
Wire.begin();
Wire.setClock(100000);
seg.begin();
seg.displayOn();
seg.setDigits(4);

View File

@ -17,13 +17,17 @@ void setup()
{
Serial.begin(115200);
Serial.println(__FILE__);
Serial.print("HT16K33_LIB_VERSION: ");
Serial.println(HT16K33_LIB_VERSION);
seg.begin();
Wire.begin();
Wire.setClock(100000);
seg.begin();
seg.displayOn();
seg.brightness(2);
seg.setBrightness(2);
seg.displayClear();
seg.blink(0);
seg.setBlink(0);
}

View File

@ -15,13 +15,17 @@ void setup()
{
Serial.begin(115200);
Serial.println(__FILE__);
Serial.print("HT16K33_LIB_VERSION: ");
Serial.println(HT16K33_LIB_VERSION);
seg.begin();
Wire.begin();
Wire.setClock(100000);
seg.begin();
seg.displayOn();
seg.brightness(2);
seg.setBrightness(2);
seg.displayClear();
seg.blink(0);
seg.setBlink(0);
}

View File

@ -17,13 +17,17 @@ void setup()
{
Serial.begin(115200);
Serial.println(__FILE__);
Serial.print("HT16K33_LIB_VERSION: ");
Serial.println(HT16K33_LIB_VERSION);
seg.begin();
Wire.begin();
Wire.setClock(100000);
seg.begin();
seg.displayOn();
seg.brightness(2);
seg.setBrightness(2);
seg.displayClear();
seg.blink(0);
seg.setBlink(0);
seg.cacheOff();
start = millis();

View File

@ -17,9 +17,13 @@ void setup()
{
Serial.begin(115200);
Serial.println(__FILE__);
Serial.print("HT16K33_LIB_VERSION: ");
Serial.println(HT16K33_LIB_VERSION);
seg.begin();
Wire.begin();
Wire.setClock(100000);
seg.begin();
seg.displayOn();
seg.setDigits(4);
}

View File

@ -15,9 +15,13 @@ void setup()
{
Serial.begin(115200);
Serial.println(__FILE__);
Serial.print("HT16K33_LIB_VERSION: ");
Serial.println(HT16K33_LIB_VERSION);
seg.begin();
Wire.begin();
Wire.setClock(100000);
seg.begin();
seg.displayOn();
seg.setDigits(4);

View File

@ -18,12 +18,15 @@ void setup()
{
Serial.begin(115200);
Serial.println(__FILE__);
Serial.print("HT16K33_LIB_VERSION: ");
Serial.println(HT16K33_LIB_VERSION);
Wire.begin();
Wire.setClock(100000);
left.begin();
right.begin();
Wire.setClock(100000);
left.displayOn();
right.displayOn();

View File

@ -23,9 +23,13 @@ void setup()
{
Serial.begin(115200);
Serial.println(__FILE__);
Serial.print("HT16K33_LIB_VERSION: ");
Serial.println(HT16K33_LIB_VERSION);
Wire.begin();
Wire.setClock(100000);
seg.begin();
seg.displayOn();
}

View File

@ -15,12 +15,17 @@ void setup()
{
Serial.begin(115200);
Serial.println(__FILE__);
Serial.print("HT16K33_LIB_VERSION: ");
Serial.println(HT16K33_LIB_VERSION);
Wire.begin();
Wire.setClock(100000);
if (! seg.begin())
{
Serial.println("not connected");
}
Wire.setClock(100000);
seg.displayOn();
seg.displayFixedPoint0(1.945);

View File

@ -15,12 +15,16 @@ void setup()
{
Serial.begin(115200);
Serial.println(__FILE__);
Serial.print("HT16K33_LIB_VERSION: ");
Serial.println(HT16K33_LIB_VERSION);
Wire.begin();
Wire.setClock(100000);
if (! seg.begin())
{
Serial.println("not connected");
}
Wire.setClock(100000);
seg.displayOn();
seg.displayFloat(1.945, 3);

View File

@ -16,9 +16,12 @@ void setup()
{
Serial.begin(115200);
Serial.println(__FILE__);
Serial.print("HT16K33_LIB_VERSION: ");
Serial.println(HT16K33_LIB_VERSION);
seg.begin();
Wire.begin();
Wire.setClock(100000);
seg.begin();
seg.displayOn();

View File

@ -15,9 +15,12 @@ void setup()
{
Serial.begin(115200);
Serial.println(__FILE__);
Serial.print("HT16K33_LIB_VERSION: ");
Serial.println(HT16K33_LIB_VERSION);
seg.begin();
Wire.begin();
Wire.setClock(100000);
seg.begin();
seg.displayOn();
}

View File

@ -15,7 +15,7 @@
"type": "git",
"url": "https://github.com/RobTillaart/HT16K33.git"
},
"version": "0.3.9",
"version": "0.4.0",
"license": "MIT",
"frameworks": "*",
"platforms": "*",

View File

@ -1,5 +1,5 @@
name=HT16K33
version=0.3.9
version=0.4.0
author=Rob Tillaart <rob.tillaart@gmail.com>
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
sentence=Arduino Library for HT16K33 I2C 4x7segment display

View File

@ -43,6 +43,7 @@ unittest(test_constructor)
{
HT16K33 seg(0x70);
Wire.begin();
fprintf(stderr, "None of the functions return anything...\n");
assertEqual(1, 1);
@ -79,5 +80,5 @@ unittest(test_constants)
unittest_main()
// --END OF FILE --
// -- END OF FILE --