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
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//
9091HT16K33::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
122123bool 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
543544void 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)
551552void 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+
0 commit comments