HT16K33 0.3.3

This commit is contained in:
rob tillaart 2021-05-26 15:01:19 +02:00
parent b313a084f5
commit 9162635d8a
18 changed files with 83 additions and 24 deletions

View File

@ -1,7 +1,7 @@
//
// FILE: HT16K33.cpp
// AUTHOR: Rob Tillaart
// VERSION: 0.3.2
// VERSION: 0.3.3
// DATE: 2019-02-07
// PURPOSE: Arduino Library for HT16K33 4x7segment display
// URL: https://github.com/RobTillaart/HT16K33
@ -24,9 +24,12 @@
// add refresh(), // experimental
// add getOverflow(); // experimental
// add displayFloat(f, decimals); // experimental
// 0.3.3 2021-05-26 fix #17 add leadingZero flag in displayTIme() [Kudos to OwenDuffy]
#include "HT16K33.h"
// Commands
#define HT16K33_ON 0x21 // 0=off 1=on
#define HT16K33_STANDBY 0x20 // bit xxxxxxx0
@ -127,7 +130,7 @@ void HT16K33::reset()
{
displayOn();
displayClear();
setDigits(1);
setDigits(1);
clearCache();
brightness(8);
}
@ -255,12 +258,14 @@ bool HT16K33::displayHex(uint16_t n)
// 00.00 .. 99.99
bool HT16K33::displayDate(uint8_t left, uint8_t right)
bool HT16K33::displayDate(uint8_t left, uint8_t right, bool lz)
{
bool inRange = ((left < 100) && (right < 100));
uint8_t x[4];
x[0] = left / 10;
x[1] = left - x[0] * 10;
if (!lz && (x[0] == 0)) x[0] = HT16K33_SPACE;
x[2] = right / 10;
x[3] = right - x[2] * 10;
display(x, 1);
@ -270,12 +275,14 @@ bool HT16K33::displayDate(uint8_t left, uint8_t right)
// 00:00 .. 99:99
bool HT16K33::displayTime(uint8_t left, uint8_t right, bool colon)
bool HT16K33::displayTime(uint8_t left, uint8_t right, bool colon, bool lz)
{
bool inRange = ((left < 100) && (right < 100));
uint8_t x[4];
x[0] = left / 10;
x[1] = left - x[0] * 10;
if (!lz && (x[0] == 0)) x[0] = HT16K33_SPACE;
x[2] = right / 10;
x[3] = right - x[2] * 10;
display(x);
@ -285,11 +292,11 @@ bool HT16K33::displayTime(uint8_t left, uint8_t right, bool colon)
// seconds / minutes max 6039 == 99:99
bool HT16K33::displaySeconds(uint16_t seconds, bool colon)
bool HT16K33::displaySeconds(uint16_t seconds, bool colon, bool lz)
{
uint8_t left = seconds / 60;
uint8_t right = seconds - left * 60;
return displayTime(left, right, colon);
return displayTime(left, right, colon, lz);
}

View File

@ -2,7 +2,7 @@
//
// FILE: HT16K33.h
// AUTHOR: Rob Tillaart
// VERSION: 0.3.2
// VERSION: 0.3.3
// DATE: 2019-02-07
// PURPOSE: Arduino Library for HT16K33 4x7segment display
// http://www.adafruit.com/products/1002
@ -14,7 +14,7 @@
#include "Wire.h"
#define HT16K33_LIB_VERSION (F("0.3.2"))
#define HT16K33_LIB_VERSION (F("0.3.3"))
// Characters
@ -78,9 +78,10 @@ public:
// Date could be {month.day} or {day.hour} . as separator
// Time could be hh:mm or mm:ss or ss:uu (hundreds : as separator
bool displayDate(uint8_t left, uint8_t right); // 00.00 .. 99.99
bool displayTime(uint8_t left, uint8_t right, bool colon = true); // 00:00 .. 99:99
bool displaySeconds(uint16_t seconds, bool colon = true); // 00:00 .. 99:99
// colon displays : lz = Leading Zero or space
bool displayDate(uint8_t left, uint8_t right, bool lz = true); // 00.00 .. 99.99
bool displayTime(uint8_t left, uint8_t right, bool colon = true, bool lz = true); // 00:00 .. 99:99
bool displaySeconds(uint16_t seconds, bool colon = true, bool lz = true); // 00:00 .. 99:99
bool displayFloat(float f, uint8_t decimals = 3); // -999 .. 0.000 .. 9999

View File

@ -78,14 +78,19 @@ Returns false if device not seen on I2C bus.
The bool return value indicates that the value displayed is in range.
- **void displayClear()** empty display
- **void displayClear()** fill display with spaces => results in an empty display.
- **bool displayInt(n)** values -999 .. 9999
- **bool displayHex(n)** values 0000 .. FFFF
- **bool displayDate(left, right)** values 00.00..99.99 Date could be {month.day} or {day.hour} . as separator
- **bool displayTime(left, right, colon = true)** values 00:00..99:99 Time could be hh:mm or mm:ss or ss:uu (hundreds) : as separator.
Optional the colon is set to false (to simulate blink)
- **void seconds(seconds, colon)** displays 00:00..99:99 units in seconds (or minutes) - splits % 60 : as separator
Optional the colon is set to false (to simulate blink).
- **bool displayDate(left, right, lz = true)** values 00.00..99.99 Date could be {month.day} or {day.hour}
It uses **.** as separator. Optional the leading zero (lz)
can be replaced by a space to look more natural e.g 1:54 iso 01:54
- **bool displayTime(left, right, colon = true, lz = true)** values 00:00..99:99
Time could be hh:mm or mm:ss or ss:uu (hundreds), it uses **:** as separator.
Optional the colon is set to false (e.g. to simulate blink) and optional the leading zero (lz)
can be replaced by a space to look more natural e.g 1:54 iso 01:54
- **void seconds(seconds, colon, lz = true)** displays 00:00..99:99 units in seconds (or minutes) - splits % 60 : as separator
Optional the colon is set to false (to simulate blink).
Optional the leading zero (lz) can be replaced by a space to look more natural e.g 1:54 iso 01:54
- **bool displayFloat(f, decimals = 3)** values -999..0.000..9999
The number of decimals = 0,1,2,3 = default. When less decimals are displayed, the number will be right aligned.

View File

@ -6,12 +6,14 @@
// URL: http://www.adafruit.com/products/1002
// URL: https://github.com/RobTillaart/HT16K33
#include "HT16K33.h"
HT16K33 seg(0x70);
uint32_t start, stop;
void setup()
{
Serial.begin(115200);
@ -28,6 +30,7 @@ void setup()
seg.displayOn();
}
void loop()
{
Serial.println("Int");

View File

@ -8,12 +8,14 @@
// connect potmeter or so to A0 and A1 for the VU tests
#include "HT16K33.h"
HT16K33 seg(0x70);
uint32_t start, stop;
uint8_t ar[4];
void setup()
{
Serial.begin(115200);
@ -33,6 +35,7 @@ void setup()
seg.displayColon(false);
}
void loop()
{
test_VULeft();
@ -43,6 +46,7 @@ void loop()
delay(1000);
}
void test_VULeft()
{
for (uint8_t run = 0; run < 50; run++)
@ -53,6 +57,7 @@ void test_VULeft()
}
}
void test_VURight()
{
for (uint8_t run = 0; run < 50; run++)
@ -64,6 +69,7 @@ void test_VURight()
}
}
void test_VUStereo()
{
for (uint8_t run = 0; run < 50; run++)
@ -77,6 +83,7 @@ void test_VUStereo()
}
}
void displayVUStereo(uint8_t left, uint8_t right)
{
switch (left)
@ -135,4 +142,5 @@ void displayVUStereo(uint8_t left, uint8_t right)
hb = !hb;
}
// -- END OF FILE --

View File

@ -6,12 +6,14 @@
// URL: http://www.adafruit.com/products/1002
// URL: https://github.com/RobTillaart/HT16K33
#include "HT16K33.h"
HT16K33 seg(0x70);
uint32_t start, stop, d1, d2;
void setup()
{
Serial.begin(115200);
@ -25,6 +27,7 @@ void setup()
seg.blink(0);
}
void loop()
{
// Note: UNO fails for speed above 850K
@ -37,6 +40,7 @@ void loop()
Serial.println();
}
void test_cache(uint32_t speed)
{
Wire.setClock(speed);

View File

@ -6,10 +6,12 @@
// URL: http://www.adafruit.com/products/1002
// URL: https://github.com/RobTillaart/HT16K33
#include "HT16K33.h"
HT16K33 seg(0x70);
void setup()
{
Serial.begin(115200);
@ -23,6 +25,7 @@ void setup()
seg.blink(0);
}
void loop()
{
Serial.print("INT TEST 0:\t");

View File

@ -6,12 +6,14 @@
// URL: http://www.adafruit.com/products/1002
// URL: https://github.com/RobTillaart/HT16K33
#include "HT16K33.h"
HT16K33 seg(0x70);
uint32_t start, stop, d1, d2;
void setup()
{
Serial.begin(115200);
@ -35,6 +37,7 @@ void setup()
Serial.println(millis() - start);
}
void loop()
{
uint8_t x[4] = { 255, 255, 255, 255 };
@ -53,6 +56,7 @@ void loop()
delay(1000);
}
void test_elsa()
{
uint8_t ar[4];
@ -63,6 +67,7 @@ void test_elsa()
seg.displayRaw(ar);
}
void test_random()
{
uint8_t ar[4];

View File

@ -1,7 +1,7 @@
//
// FILE: demo_displayTime.ino
// AUTHOR: Rob Tillaart
// VERSION: 0.2.0
// VERSION: 0.2.1
// PURPOSE: demo
// URL: http://www.adafruit.com/products/1002
// URL: https://github.com/RobTillaart/HT16K33
@ -13,6 +13,7 @@
HT16K33 seg(0x70);
void setup()
{
Serial.begin(115200);
@ -24,6 +25,7 @@ void setup()
seg.setDigits(4);
}
void loop()
{
static uint32_t last = 0;
@ -34,9 +36,11 @@ void loop()
uint32_t s = now / 1000;
uint32_t t = (now - s * 1000) / 10;
s = s % 100;
seg.displayTime(s, t);
// seg.displayTime(s, t);
seg.displayTime(s, t, true, false); // do not display leading zero.
seg.displayColon(1);
}
}
// -- END OF FILE --

View File

@ -6,6 +6,7 @@
// URL: http://www.adafruit.com/products/1002
// URL: https://github.com/RobTillaart/HT16K33
#include "HT16K33.h"
HT16K33 left(0x71);
@ -13,6 +14,7 @@ HT16K33 right(0x70);
uint32_t counter = 0;
void setup()
{
Serial.begin(115200);
@ -29,6 +31,7 @@ void setup()
Serial.println("dual displayTest");
}
void loop()
{
display_ulong(counter);
@ -37,6 +40,7 @@ void loop()
counter++;
}
void display_ulong(uint32_t value)
{
uint16_t lval = value / 10000;

View File

@ -19,6 +19,7 @@ DHTNEW dht(10);
uint32_t lastTime = 0;
bool flag = true;
void setup()
{
Serial.begin(115200);
@ -29,6 +30,7 @@ void setup()
seg.displayOn();
}
void loop()
{
@ -50,4 +52,5 @@ void loop()
}
}
// -- END OF FILE --

View File

@ -9,9 +9,9 @@
#include "HT16K33.h"
HT16K33 seg(0x70);
void setup()
{
Serial.begin(115200);

View File

@ -6,10 +6,12 @@
// URL: http://www.adafruit.com/products/1002
// URL: https://github.com/RobTillaart/HT16K33
#include "HT16K33.h"
HT16K33 seg(0x70);
void setup()
{
Serial.begin(115200);

View File

@ -6,6 +6,7 @@
// URL: http://www.adafruit.com/products/1002
// URL: https://github.com/RobTillaart/HT16K33
#include "HT16K33.h"
@ -25,10 +26,12 @@ void setup()
test_out_of_range();
}
void loop()
{
}
void test_out_of_range()
{
bool b = true;

View File

@ -6,10 +6,12 @@
// URL: http://www.adafruit.com/products/1002
// URL: https://github.com/RobTillaart/HT16K33
#include "HT16K33.h"
HT16K33 seg(0x70);
void setup()
{
Serial.begin(115200);
@ -21,6 +23,7 @@ void setup()
seg.displayOn();
}
void loop()
{
test_printfloat();
@ -28,6 +31,7 @@ void loop()
delay(1000);
}
void test_printfloat()
{
for (int i = -2000; i < 2000; i++)
@ -56,4 +60,5 @@ void test_printfloat()
}
}
// -- END OF FILE --

View File

@ -3,6 +3,7 @@
# Datatypes (KEYWORD1)
HT16K33 KEYWORD1
# Methods and Functions (KEYWORD2)
HT16K33 KEYWORD2

View File

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

View File

@ -1,9 +1,9 @@
name=HT16K33
version=0.3.2
version=0.3.3
author=Rob Tillaart <rob.tillaart@gmail.com>
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
sentence=Arduino Library for HT16K33
paragraph=Arduino Library for HT16K33 I2C 4x7segment display
sentence=Arduino Library for HT16K33 I2C 4x7segment display
paragraph=Has display functions for time date float int etc.
category=Signal Input/Output
url=https://github.com/RobTillaart/HT16K33
architectures=*