Skip to content

Commit 62fd440

Browse files
authored
update library.json, license, refactor (#20)
1 parent fbd14de commit 62fd440

File tree

20 files changed

+148
-132
lines changed

20 files changed

+148
-132
lines changed

HT16K33.cpp

Lines changed: 61 additions & 59 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.3
4+
// VERSION: 0.3.4
55
// DATE: 2019-02-07
66
// PURPOSE: Arduino Library for HT16K33 4x7segment display
77
// URL: https://github.com/RobTillaart/HT16K33
@@ -19,12 +19,13 @@
1919
// 0.2.3 2020-10-09 issue #4 add negative values for displayInt()
2020
// 0.2.4 2020-10-10 refactor #5 setDigits() iso suppressLeadingZeroPlaces()
2121
// 0.3.0 2020-10-12 negative float, cache control, extend displayRaw()
22-
// 0.3.1 2020-12-28 arduino-CI, unit test (framework only),
23-
// 0.3.2 2021-01-14 add WireN suppoprt,
22+
// 0.3.1 2020-12-28 Arduino-CI, unit test (framework only),
23+
// 0.3.2 2021-01-14 add WireN support,
2424
// add refresh(), // experimental
2525
// add getOverflow(); // experimental
2626
// add displayFloat(f, decimals); // experimental
2727
// 0.3.3 2021-05-26 fix #17 add leadingZero flag in displayTIme() [Kudos to OwenDuffy]
28+
// 0.3.4 2021-12-19 update library.json, license, minor edits
2829

2930

3031
#include "HT16K33.h"
@@ -89,7 +90,7 @@ static const uint8_t charmap[] = { // TODO PROGMEM ?
8990
//
9091
HT16K33::HT16K33(const uint8_t address, TwoWire *wire)
9192
{
92-
_addr = address;
93+
_address = address;
9394
_wire = wire;
9495
}
9596

@@ -121,7 +122,7 @@ bool HT16K33::begin()
121122

122123
bool HT16K33::isConnected()
123124
{
124-
_wire->beginTransmission(_addr);
125+
_wire->beginTransmission(_address);
125126
return (0 == _wire->endTransmission());
126127
}
127128

@@ -166,31 +167,31 @@ void HT16K33::refresh()
166167
}
167168

168169

169-
void HT16K33::blink(uint8_t val)
170+
void HT16K33::blink(uint8_t value)
170171
{
171-
if (val > 0x03) val = 0x00;
172-
writeCmd(HT16K33_BLINKOFF | (val << 1) );
172+
if (value > 0x03) value = 0x00;
173+
writeCmd(HT16K33_BLINKOFF | (value << 1) );
173174
}
174175

175176

176-
void HT16K33::brightness(uint8_t val)
177+
void HT16K33::brightness(uint8_t value)
177178
{
178-
if (val == _bright) return;
179-
_bright = val;
179+
if (value == _bright) return;
180+
_bright = value;
180181
if (_bright > 0x0F) _bright = 0x0F;
181182
writeCmd(HT16K33_BRIGHTNESS | _bright);
182183
}
183184

184185

185-
void HT16K33::setDigits(uint8_t val)
186+
void HT16K33::setDigits(uint8_t value)
186187
{
187-
_digits = val > 4 ? 4 : val;
188+
_digits = value > 4 ? 4 : value;
188189
}
189190

190191

191-
void HT16K33::suppressLeadingZeroPlaces(uint8_t val)
192+
void HT16K33::suppressLeadingZeroPlaces(uint8_t value)
192193
{
193-
_digits = val > 4 ? 0 : 4 - val;
194+
_digits = value > 4 ? 0 : 4 - value;
194195
}
195196

196197

@@ -313,8 +314,8 @@ bool HT16K33::displayFloat(float f, uint8_t decimals)
313314

314315
int whole = f;
315316
int point = 3;
316-
if (whole < 1000) point = 2;
317-
if (whole < 100) point = 1;
317+
if (whole < 1000) point = 2;
318+
if (whole < 100) point = 1;
318319
if (whole < 10) point = 0;
319320

320321
if (f >= 1)
@@ -406,31 +407,31 @@ void HT16K33::displayTest(uint8_t del)
406407
}
407408

408409

409-
void HT16K33::displayRaw(uint8_t *arr, bool colon)
410+
void HT16K33::displayRaw(uint8_t *array, bool colon)
410411
{
411-
writePos(0, arr[0]);
412-
writePos(1, arr[1]);
413-
writePos(3, arr[2]);
414-
writePos(4, arr[3]);
412+
writePos(0, array[0]);
413+
writePos(1, array[1]);
414+
writePos(3, array[2]);
415+
writePos(4, array[3]);
415416
writePos(2, colon ? 255 : 0);
416417
}
417418

418419

419-
bool HT16K33::displayVULeft(uint8_t val)
420+
bool HT16K33::displayVULeft(uint8_t value)
420421
{
421-
bool inRange = (val < 9); // can display 0..8 bars
422+
bool inRange = (value < 9); // can display 0..8 bars
422423
uint8_t ar[4];
423424
for (int idx = 3; idx >=0; idx--)
424425
{
425-
if (val >= 2)
426+
if (value >= 2)
426427
{
427428
ar[idx] = 0x36; // ||
428-
val -= 2;
429+
value -= 2;
429430
}
430-
else if (val == 1)
431+
else if (value == 1)
431432
{
432433
ar[idx] = 0x06; // _|
433-
val = 0;
434+
value = 0;
434435
}
435436
else ar[idx] = 0x00; // __
436437
}
@@ -439,21 +440,21 @@ bool HT16K33::displayVULeft(uint8_t val)
439440
}
440441

441442

442-
bool HT16K33::displayVURight(uint8_t val)
443+
bool HT16K33::displayVURight(uint8_t value)
443444
{
444-
bool inRange = (val < 9);
445+
bool inRange = (value < 9);
445446
uint8_t ar[4];
446447
for (uint8_t idx = 0; idx < 4; idx++)
447448
{
448-
if (val >= 2)
449+
if (value >= 2)
449450
{
450451
ar[idx] = 0x36; // ||
451-
val -= 2;
452+
value -= 2;
452453
}
453-
else if (val == 1)
454+
else if (value == 1)
454455
{
455456
ar[idx] = 0x30; // |_
456-
val = 0;
457+
value = 0;
457458
}
458459
else ar[idx] = 0x00; // __
459460
}
@@ -462,32 +463,32 @@ bool HT16K33::displayVURight(uint8_t val)
462463
}
463464

464465

465-
void HT16K33::display(uint8_t *arr)
466+
void HT16K33::display(uint8_t *array)
466467
{
467468
for (uint8_t i = 0; i < (4 - _digits); i++)
468469
{
469-
if (arr[i] != 0) break;
470-
arr[i] = HT16K33_SPACE;
470+
if (array[i] != 0) break;
471+
array[i] = HT16K33_SPACE;
471472
}
472-
writePos(0, charmap[arr[0]]);
473-
writePos(1, charmap[arr[1]]);
474-
writePos(3, charmap[arr[2]]);
475-
writePos(4, charmap[arr[3]]);
473+
writePos(0, charmap[array[0]]);
474+
writePos(1, charmap[array[1]]);
475+
writePos(3, charmap[array[2]]);
476+
writePos(4, charmap[array[3]]);
476477

477478
// debug to Serial
478-
// dumpSerial(arr, 0);
479+
// dumpSerial(array, 0);
479480
}
480481

481482

482-
void HT16K33::display(uint8_t *arr, uint8_t pnt)
483+
void HT16K33::display(uint8_t *array, uint8_t point)
483484
{
484485
// debug to Serial
485-
// dumpSerial(arr, pnt);
486+
// dumpSerial(array, point);
486487

487-
writePos(0, charmap[arr[0]], pnt == 0);
488-
writePos(1, charmap[arr[1]], pnt == 1);
489-
writePos(3, charmap[arr[2]], pnt == 2);
490-
writePos(4, charmap[arr[3]], pnt == 3);
488+
writePos(0, charmap[array[0]], point == 0);
489+
writePos(1, charmap[array[1]], point == 1);
490+
writePos(3, charmap[array[2]], point == 2);
491+
writePos(4, charmap[array[3]], point == 3);
491492
}
492493

493494

@@ -497,18 +498,18 @@ void HT16K33::displayColon(uint8_t on)
497498
}
498499

499500

500-
void HT16K33::dumpSerial(uint8_t *arr, uint8_t pnt)
501+
void HT16K33::dumpSerial(uint8_t *array, uint8_t point)
501502
{
502503
// to debug without display
503504
for (int i = 0; i < 4; i++)
504505
{
505-
if (arr[i] == HT16K33_SPACE) Serial.print(" ");
506-
else if (arr[i] == HT16K33_MINUS) Serial.print("-");
507-
else Serial.print(arr[i]);
508-
if (i == pnt) Serial.print(".");
506+
if (array[i] == HT16K33_SPACE) Serial.print(" ");
507+
else if (array[i] == HT16K33_MINUS) Serial.print("-");
508+
else Serial.print(array[i]);
509+
if (i == point) Serial.print(".");
509510
}
510511
Serial.print(" ");
511-
Serial.println(pnt);
512+
Serial.println(point);
512513
}
513514

514515

@@ -533,7 +534,7 @@ void HT16K33::_refresh()
533534
{
534535
for (uint8_t pos = 0; pos < 4; pos++)
535536
{
536-
_wire->beginTransmission(_addr);
537+
_wire->beginTransmission(_address);
537538
_wire->write(pos * 2);
538539
_wire->write(_displayCache[pos]);
539540
_wire->endTransmission();
@@ -542,7 +543,7 @@ void HT16K33::_refresh()
542543

543544
void HT16K33::writeCmd(uint8_t cmd)
544545
{
545-
_wire->beginTransmission(_addr);
546+
_wire->beginTransmission(_address);
546547
_wire->write(cmd);
547548
_wire->endTransmission();
548549
}
@@ -551,21 +552,22 @@ void HT16K33::writeCmd(uint8_t cmd)
551552
void HT16K33::writePos(uint8_t pos, uint8_t mask)
552553
{
553554
if (_cache && (_displayCache[pos] == mask)) return;
554-
_wire->beginTransmission(_addr);
555+
_wire->beginTransmission(_address);
555556
_wire->write(pos * 2);
556557
_wire->write(mask);
557558
_wire->endTransmission();
558559
_displayCache[pos] = _cache ? mask : HT16K33_NONE;
559560
}
560561

561562

562-
void HT16K33::writePos(uint8_t pos, uint8_t mask, bool pnt)
563+
void HT16K33::writePos(uint8_t pos, uint8_t mask, bool point)
563564
{
564-
if (pnt) mask |= 0x80;
565+
if (point) mask |= 0x80;
565566
// if (_overflow) mask |= 0x80;
566567
else mask &= 0x7F;
567568
writePos(pos, mask);
568569
}
569570

570571

571572
// -- END OF FILE --
573+

HT16K33.h

Lines changed: 25 additions & 20 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.3
5+
// VERSION: 0.3.4
66
// DATE: 2019-02-07
77
// PURPOSE: Arduino Library for HT16K33 4x7segment display
88
// http://www.adafruit.com/products/1002
@@ -14,7 +14,7 @@
1414
#include "Wire.h"
1515

1616

17-
#define HT16K33_LIB_VERSION (F("0.3.3"))
17+
#define HT16K33_LIB_VERSION (F("0.3.4"))
1818

1919

2020
// Characters
@@ -59,18 +59,18 @@ class HT16K33
5959
void cacheOn() { _cache = true; };
6060
void cacheOff() { _cache = false; };
6161
void refresh(); // force writing of cache to display
62-
62+
6363
void displayOn();
6464
void displayOff();
6565

66-
void brightness(uint8_t val); // 0 .. 15
67-
void blink(uint8_t val); // 0 .. 3 0 = off
66+
void brightness(uint8_t value); // 0 .. 15
67+
void blink(uint8_t value); // 0 .. 3 0 = off
6868

6969

7070
// 0,1,2,3,4 digits - will replace suppressLeadingZeroPlaces
71-
void setDigits(uint8_t val);
72-
// 0 = off, 1,2,3,4 digits space iso 0
73-
void suppressLeadingZeroPlaces(uint8_t val); // will be obsolete
71+
void setDigits(uint8_t value);
72+
// 0 = off, 1,2,3,4 digits space instead of 0
73+
void suppressLeadingZeroPlaces(uint8_t value); // will be obsolete
7474

7575
void displayClear();
7676
bool displayInt(int n); // -999 .. 9999
@@ -85,20 +85,23 @@ class HT16K33
8585

8686
bool displayFloat(float f, uint8_t decimals = 3); // -999 .. 0.000 .. 9999
8787

88-
void display(uint8_t *arr); // array with 4 elements
89-
void display(uint8_t *arr, uint8_t pt); // pt = digit with . (0..3)
90-
void displayColon(uint8_t on); // 0 = off
91-
void displayRaw(uint8_t *arr, bool colon = false); // max control
88+
void display(uint8_t *array); // array with 4 elements
89+
void display(uint8_t *array, uint8_t point); // point = digit with . (0..3)
90+
void displayColon(uint8_t on); // 0 = off
91+
void displayRaw(uint8_t *array, bool colon = false); // max control
9292

93-
bool displayVULeft(uint8_t val); // 0..8
94-
bool displayVURight(uint8_t val); // 0..8
93+
bool displayVULeft(uint8_t value); // 0..8
94+
bool displayVURight(uint8_t value); // 0..8
9595

9696

9797
// DEBUG
9898
void displayTest(uint8_t del);
99-
void dumpSerial(uint8_t *arr, uint8_t pnt); // array as numbers
100-
void dumpSerial(); // display cache in HEX format
101-
uint8_t getAddr() { return _addr; };
99+
// array as numbers
100+
void dumpSerial(uint8_t *array, uint8_t point);
101+
// display cache in HEX format
102+
void dumpSerial();
103+
uint8_t getAddress() { return _address; };
104+
uint8_t getAddr() { return getAddress(); }; // TODO obsolete in future
102105

103106

104107
// EXPERIMENTAL
@@ -115,18 +118,20 @@ class HT16K33
115118
void _refresh();
116119
void writeCmd(uint8_t cmd);
117120
void writePos(uint8_t pos, uint8_t mask);
118-
void writePos(uint8_t pos, uint8_t mask, bool pnt);
121+
void writePos(uint8_t pos, uint8_t mask, bool point);
119122

120-
uint8_t _addr;
123+
uint8_t _address;
121124
uint8_t _displayCache[5]; // for performance
122125
bool _cache = true;
123126
uint8_t _digits = 0;
124127
uint8_t _bright;
125128

126129
TwoWire* _wire;
127-
130+
128131
// EXPERIMENTAL
129132
bool _overflow = false;
130133
};
131134

135+
132136
// -- END OF FILE --
137+

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2019-2021 Rob Tillaart
3+
Copyright (c) 2019-2022 Rob Tillaart
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

0 commit comments

Comments
 (0)