Skip to content

Commit 030e459

Browse files
authored
refactor API, begin() (#27)
- refactor API, begin() - update readme.md - remove obsolete getAddr() => **getAddress()** - rename brightness() => **setBrightness()** - add **getBrightness()** - rename blink() ==> **setBlink()** - add **getBlink()** - minor edits
1 parent 1046b3a commit 030e459

File tree

22 files changed

+180
-112
lines changed

22 files changed

+180
-112
lines changed

CHANGELOG.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,22 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
66
and this project adheres to [Semantic Versioning](http://semver.org/).
77

88

9+
## [0.4.0] - 2023-12-05
10+
- refactor API, begin()
11+
- update readme.md
12+
- remove obsolete getAddr() => **getAddress()**
13+
- rename brightness() => **setBrightness()**
14+
- add **getBrightness()**
15+
- rename blink() ==> **setBlink()**
16+
- add **getBlink()**
17+
- minor edits
18+
19+
----
20+
921
## [0.3.9] - 2023-09-22
1022
- add Wire1 support for ESP32
1123
- update readme.md
1224

13-
1425
## [0.3.8] - 2023-02-26
1526
- add **getBrightness()**
1627
- moved code to .cpp file (prep 0.4.0)
@@ -20,7 +31,6 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
2031
- update license 2023
2132
- minor edits
2233

23-
2434
## [0.3.7] - 2022-11-19
2535
- add displayUnit(float, char);
2636
- add top c symbol

HT16K33.cpp

Lines changed: 24 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// FILE: HT16K33.cpp
33
// AUTHOR: Rob Tillaart
4-
// VERSION: 0.3.9
4+
// VERSION: 0.4.0
55
// DATE: 2019-02-07
66
// PURPOSE: Arduino Library for HT16K33 4x7segment display
77
// URL: https://github.com/RobTillaart/HT16K33
@@ -76,25 +76,8 @@ HT16K33::HT16K33(const uint8_t address, TwoWire *wire)
7676
}
7777

7878

79-
#if defined (ESP8266) || defined(ESP32)
80-
bool HT16K33::begin(uint8_t sda, uint8_t scl)
81-
{
82-
if ((sda < 255) && (scl < 255))
83-
{
84-
_wire->begin(sda, scl);
85-
} else {
86-
_wire->begin();
87-
}
88-
if (! isConnected()) return false;
89-
reset();
90-
return true;
91-
}
92-
#endif
93-
94-
9579
bool HT16K33::begin()
9680
{
97-
_wire->begin();
9881
if (! isConnected()) return false;
9982
reset();
10083
return true;
@@ -113,7 +96,8 @@ void HT16K33::reset()
11396
displayClear();
11497
setDigits(1);
11598
clearCache();
116-
brightness(8);
99+
setBrightness(8);
100+
setBlink(0);
117101
}
118102

119103

@@ -136,7 +120,6 @@ void HT16K33::cacheOn()
136120
}
137121

138122

139-
140123
void HT16K33::cacheOff()
141124
{
142125
_cache = false;
@@ -157,7 +140,7 @@ void HT16K33::displayOn()
157140
{
158141
writeCmd(HT16K33_ON);
159142
writeCmd(HT16K33_DISPLAYON);
160-
brightness(_bright);
143+
setBrightness(_bright);
161144
}
162145

163146

@@ -168,14 +151,21 @@ void HT16K33::displayOff()
168151
}
169152

170153

171-
void HT16K33::blink(uint8_t value)
154+
void HT16K33::setBlink(uint8_t value)
172155
{
173156
if (value > 0x03) value = 0x00;
157+
_blink = value;
174158
writeCmd(HT16K33_BLINKOFF | (value << 1) );
175159
}
176160

177161

178-
void HT16K33::brightness(uint8_t value)
162+
uint8_t HT16K33::getBlink()
163+
{
164+
return _blink;
165+
}
166+
167+
168+
void HT16K33::setBrightness(uint8_t value)
179169
{
180170
if (value == _bright) return;
181171
_bright = value;
@@ -196,6 +186,12 @@ void HT16K33::setDigits(uint8_t value)
196186
}
197187

198188

189+
uint8_t HT16K33::getDigits()
190+
{
191+
return _digits;
192+
}
193+
194+
199195
void HT16K33::suppressLeadingZeroPlaces(uint8_t value)
200196
{
201197
_digits = value > 4 ? 0 : 4 - value;
@@ -433,27 +429,31 @@ bool HT16K33::displayFixedPoint0(float f)
433429
return inRange;
434430
}
435431

432+
436433
bool HT16K33::displayFixedPoint1(float f)
437434
{
438435
bool inRange = ((-99.5 < f) && (f < 999.95));
439436
displayFloat(f, 1);
440437
return inRange;
441438
}
442439

440+
443441
bool HT16K33::displayFixedPoint2(float f)
444442
{
445443
bool inRange = ((-9.95 < f) && (f < 99.995));
446444
displayFloat(f, 2);
447445
return inRange;
448446
}
449447

448+
450449
bool HT16K33::displayFixedPoint3(float f)
451450
{
452451
bool inRange = ((0 < f) && (f < 9.9995));
453452
displayFloat(f, 3);
454453
return inRange;
455454
}
456455

456+
457457
/////////////////////////////////////////////////////////////////////
458458

459459
void HT16K33::displayTest(uint8_t del)
@@ -608,11 +608,6 @@ uint8_t HT16K33::getAddress()
608608

609609

610610

611-
612-
613-
614-
615-
616611
//////////////////////////////////////////////////////////
617612
//
618613
// PRIVATE
@@ -628,6 +623,7 @@ void HT16K33::_refresh()
628623
}
629624
}
630625

626+
631627
void HT16K33::writeCmd(uint8_t cmd)
632628
{
633629
_wire->beginTransmission(_address);

HT16K33.h

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// FILE: HT16K33.h
44
// AUTHOR: Rob Tillaart
5-
// VERSION: 0.3.9
5+
// VERSION: 0.4.0
66
// DATE: 2019-02-07
77
// PURPOSE: Arduino Library for HT16K33 4x7segment display
88
// http://www.adafruit.com/products/1002
@@ -13,7 +13,7 @@
1313
#include "Wire.h"
1414

1515

16-
#define HT16K33_LIB_VERSION (F("0.3.9"))
16+
#define HT16K33_LIB_VERSION (F("0.4.0"))
1717

1818

1919
// Characters
@@ -45,12 +45,8 @@ class HT16K33
4545
public:
4646
HT16K33(const uint8_t address, TwoWire *wire = &Wire); // 0x70 .. 0x77
4747

48-
#if defined (ESP8266) || defined(ESP32)
49-
bool begin(uint8_t sda, uint8_t scl);
50-
#endif
5148
bool begin();
5249
void reset();
53-
5450
bool isConnected();
5551

5652
// default _cache is true as it is ~3x faster but if one has noise
@@ -64,13 +60,16 @@ class HT16K33
6460
void displayOn();
6561
void displayOff();
6662

67-
void brightness(uint8_t value); // 0 .. 15
63+
void setBrightness(uint8_t value); // 0 .. 15
6864
uint8_t getBrightness();
69-
void blink(uint8_t value); // 0 .. 3 0 = off
65+
void setBlink(uint8_t value); // 0 .. 3 0 = off
66+
uint8_t getBlink();
7067

7168

7269
// 0,1,2,3,4 digits - will replace suppressLeadingZeroPlaces
7370
void setDigits(uint8_t value);
71+
uint8_t getDigits();
72+
7473

7574
void displayClear();
7675
bool displayInt(int n); // -999 .. 9999
@@ -122,14 +121,14 @@ class HT16K33
122121
bool displayFixedPoint2(float f);
123122
bool displayFixedPoint3(float f);
124123

125-
126-
// OBSOLETE SOON
127-
// use getAddress(); instead.
128-
uint8_t getAddr() { return getAddress(); };
129-
130124
// use setDigits(); instead.
131125
// 0 = off, 1,2,3,4 digits space instead of 0
132-
void suppressLeadingZeroPlaces(uint8_t value);
126+
void suppressLeadingZeroPlaces(uint8_t value);
127+
128+
129+
// OBSOLETE 0.4.x
130+
void brightness(uint8_t value) { setBrightness(value); };
131+
void blink(uint8_t value) { setBlink(value); };
133132

134133

135134
private:
@@ -143,6 +142,7 @@ class HT16K33
143142
bool _cache = true;
144143
uint8_t _digits = 0;
145144
uint8_t _bright;
145+
uint8_t _blink;
146146

147147
TwoWire* _wire;
148148
};

README.md

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,15 @@ it is faster for writing on average. The actual gain depends on the
2525
application and of course the values.
2626

2727

28+
#### 0.4.0 Breaking change
29+
30+
Version 0.4.0 introduced a breaking change.
31+
You cannot set the pins in **begin()** any more.
32+
This reduces the dependency of processor dependent Wire implementations.
33+
The user has to call **Wire.begin()** and can optionally set the Wire pins
34+
before calling **begin()**.
35+
36+
2837
## Perfomance
2938

3039
Version 0.3.0 allows one to switch the caching on/off to enforce
@@ -66,13 +75,12 @@ get leading/trailing zero's correctly.
6675
#### Setup behaviour
6776

6877
- **HT16K33(const uint8_t address)** address is 0x70..0x77 depending on the jumpers A0..A2. **0x70** is default.
69-
- **bool begin(uint8_t sda, uint8_t scl)** for ESP32, select I2C pins, initialize I2C and calls **reset()**.
70-
Returns false if device not seen on I2C bus.
71-
- **bool begin()** initialize I2C and calls **reset()**.
72-
Returns false if device not seen on I2C bus.
73-
- **bool isConnected()** Returns false if device not seen on I2C bus.
78+
- **bool begin()** initialize library and calls **reset()**.
79+
Returns false if address not seen on I2C bus.
80+
- **bool isConnected()** Returns false if address not seen on I2C bus.
7481
- **void reset()** resets display.
7582

83+
7684
#### Cache
7785

7886
- **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.
8391

8492
- **void displayOn()** enable display.
8593
- **void displayOff()** disable display, fast way to darken display e.g. for energy consumption.
86-
- **void brightness(uint8_t value)** values (dim) 0..15 (bright).
87-
- **void blink(uint8_t value)** values 0..3 0 = off.
94+
- **void setBrightness(uint8_t value)** values (dim) 0..15 (bright).
95+
- **void getBrightness()** returns (dim) 0..15 (bright).
96+
- **void setBlink(uint8_t value)** values 0..3 0 = off.
97+
- **void getBlink(uint8_t value)** values 0..3 0 = off.
8898
- **void setDigits(uint8_t value)** values 0..4, minimal number of digits shown, mandatory for large numbers on dual display.
89-
- **uint8_t getAddress()** idem.
99+
90100

91101

92102
#### Data types
@@ -115,9 +125,7 @@ The unitChar must be one of the chars supported like HT16K33_C, HT16K33_TOP_C or
115125
So **displayUnit(25.6, 1, HT16K33_DEGREE)** will display **23.5°**.
116126

117127

118-
#### Experimental fixed point
119-
120-
These functions are new and still under investigation.
128+
#### Fixed point
121129

122130
- **bool displayFixedPoint0(float f)** displays values -999 .. 9999 without decimals.
123131
- **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.
137145
- **void display(uint8_t \* array, uint8_t point)** idem + point = position of the digit with point (0..3).
138146
- **void displayColon(uint8_t on)** 0 = off, all values other are on.
139147
- **void displayRaw(uint8_t \* array, bool colon)** array of 4 bytes to control one 7seg display + colon flag.
140-
- **void displayExtraLeds(uint8_t value)** switch on extra leds.
148+
- **void displayExtraLeds(uint8_t value)** switch on extra LEDs.
141149
value is in fact a bit mask see table below. 0 = all off.
142150

143151

@@ -160,12 +168,13 @@ value is in fact a bit mask see table below. 0 = all off.
160168
- **void dumpSerial(uint8_t \* array, uint8_t point)** debugging equivalent of the display.
161169
Prints to Serial.
162170
- **void dumpSerial()** print HEX codes equivalent of the display to Serial.
171+
- **uint8_t getAddress()** idem.
163172

164173

165-
#### Obsolete
174+
#### Obsolete soon
166175

167-
- suppressLeadingZeroPlaces(uint8_t value) use **setDigits()**
168-
- getAddr() use **getAddress()**
176+
- brightness() use setBrightness()
177+
- blink() use setBlink()
169178

170179

171180
## Characters supported
@@ -209,18 +218,13 @@ See examples
209218

210219
#### Must
211220

212-
Mainly for a 0.4.0
221+
Mainly for a 0.4.x
213222

214223
- **bool isDisplayOn()** and similar state functions
215224
- configuration byte: 4 bits brightness, 1 bit on off flag, 1 bit cache flag, 2 blink rate
216-
217-
225+
218226
#### Should
219227

220-
- **void setBrightness()**
221-
- **void setBlink()** and **uint8_t getBlink()**
222-
- **void getDigits()**
223-
- **FixedPoint()** regular (experimental in 0.3.2)
224228

225229

226230
#### Could
@@ -233,7 +237,6 @@ Mainly for a 0.4.0
233237
- [status] dd.d
234238
- add examples
235239
- car battery monitor (voltage divider & analogRead)
236-
-
237240
- add more "special chars"?
238241
- #define HT16K33_P Pascal / Pressure 0x73
239242
- #define HT16K33_J joule 0x0E

0 commit comments

Comments
 (0)