From bbd40fb44ba19ce11828c36f06af9faebb0f84d6 Mon Sep 17 00:00:00 2001 From: Rob Tillaart Date: Sat, 24 Sep 2022 10:00:06 +0200 Subject: [PATCH] fix #21 displayExtraLeds() (#22) * fix #21 displayExtraLeds() --- HT16K33.cpp | 16 ++++- HT16K33.h | 12 +++- README.md | 21 +++++- examples/demo2/demo2.ino | 143 +++++++++++++++++++++++++++++++++++++ examples/demo3/demo3.ino | 148 +++++++++++++++++++++++++++++++++++++++ keywords.txt | 2 + library.json | 2 +- library.properties | 2 +- 8 files changed, 339 insertions(+), 7 deletions(-) create mode 100644 examples/demo2/demo2.ino create mode 100644 examples/demo3/demo3.ino diff --git a/HT16K33.cpp b/HT16K33.cpp index 884b5f0..a4360d5 100644 --- a/HT16K33.cpp +++ b/HT16K33.cpp @@ -1,7 +1,7 @@ // // FILE: HT16K33.cpp // AUTHOR: Rob Tillaart -// VERSION: 0.3.4 +// VERSION: 0.3.5 // DATE: 2019-02-07 // PURPOSE: Arduino Library for HT16K33 4x7segment display // URL: https://github.com/RobTillaart/HT16K33 @@ -13,11 +13,13 @@ // 0.1.3 2019-10-07 fixed clear, added suppressLeadingZeroPlaces(); // 0.1.4 2019-11-28 added displayRaw(), displayVULeft(), displayVURight() // 0.1.5 2019-11-30 refactor, +// // 0.2.0 2020-06-13 ESP32 support; fix brightness bug; // 0.2.1 2020-07-15 fix #160 - decimal point // 0.2.2 2020-10-04 added displayDate() thanks to bepitama // 0.2.3 2020-10-09 issue #4 add negative values for displayInt() // 0.2.4 2020-10-10 refactor #5 setDigits() iso suppressLeadingZeroPlaces() +// // 0.3.0 2020-10-12 negative float, cache control, extend displayRaw() // 0.3.1 2020-12-28 Arduino-CI, unit test (framework only), // 0.3.2 2021-01-14 add WireN support, @@ -26,6 +28,8 @@ // add displayFloat(f, decimals); // experimental // 0.3.3 2021-05-26 fix #17 add leadingZero flag in displayTIme() [Kudos to OwenDuffy] // 0.3.4 2021-12-19 update library.json, license, minor edits +// 0.3.5 2022-09-23 fix #21 additional LEDs on the display +// used in a special layout :88:8'8 #include "HT16K33.h" @@ -498,6 +502,16 @@ void HT16K33::displayColon(uint8_t on) } +void HT16K33::displayExtraLeds(uint8_t value) +{ + if (value > 30) + { + return; // no leds. + } + writePos(2, value); +} + + void HT16K33::dumpSerial(uint8_t *array, uint8_t point) { // to debug without display diff --git a/HT16K33.h b/HT16K33.h index 1c8558d..1d6ff42 100644 --- a/HT16K33.h +++ b/HT16K33.h @@ -2,7 +2,7 @@ // // FILE: HT16K33.h // AUTHOR: Rob Tillaart -// VERSION: 0.3.4 +// VERSION: 0.3.5 // 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.4")) +#define HT16K33_LIB_VERSION (F("0.3.5")) // Characters @@ -90,6 +90,14 @@ class HT16K33 void displayColon(uint8_t on); // 0 = off void displayRaw(uint8_t *array, bool colon = false); // max control + // from issue #21 - used in special layout :88:8'8 normal = 88:88 or 8.8.8.8 + // value = 0 ==> all off. + // 2 = colon + // 4 = upper left point, left of the 1st digit + // 8 = lower left point, left of the 1st digit + // 16 = upper point between 3rd and 4th digit + void displayExtraLeds(uint8_t value); + bool displayVULeft(uint8_t value); // 0..8 bool displayVURight(uint8_t value); // 0..8 diff --git a/README.md b/README.md index a934f05..ecfd042 100644 --- a/README.md +++ b/README.md @@ -119,6 +119,20 @@ 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. +value is in fact a bit mask see table below. 0 = all off. + +#### Extra Leds table + +| mask | description | +|:------:|:--------------| +| 0x00 | all off +| 0x02 | colon. +| 0x04 | upper left point, left of the 1st digit. +| 0x08 | lower left point, left of the 1st digit. +| 0x10 | upper point between 3rd and 4th digit. + +( based upon issue #21 ) ### Debugging @@ -139,7 +153,8 @@ See examples ## Future -**0.4.0** +#### 0.4.0 + - **bool isDisplayOn()** and similar state functions - configuration byte: 4 bits brightness, 1 bit on off flag, 1 bit cache flag, 2 blink rate - **void setBrightness()** and **uint8_t getBrightness()** @@ -147,8 +162,10 @@ See examples - **void getDigits()** - **FixedPoint()** regular (experimental in 0.3.2) - overflow flag ? or not decision +- move all code to .cpp file + - even the small functions. -**unknown** +#### unknown - VU metering using halve bars allows two VU from 0..8 **new** - VU metering using halve bars allows one VU from 0..17. extension of current VUleft/right - optimize the math if possible - performance and footprint. +float + int division diff --git a/examples/demo2/demo2.ino b/examples/demo2/demo2.ino new file mode 100644 index 0000000..1b8789e --- /dev/null +++ b/examples/demo2/demo2.ino @@ -0,0 +1,143 @@ +// +// FILE: 4x7segmentI2C.ino +// AUTHOR: Rob Tillaart +// PURPOSE: demo 2 +// URL: http://www.adafruit.com/products/1002 +// URL: https://github.com/RobTillaart/HT16K33 + +#include "HT16K33.h" + +HT16K33 seg(0x70); + +uint32_t start; +uint32_t stop; + +void setup() +{ + Serial.begin(115200); + Serial.println(__FILE__); + + seg.begin(); + Wire.setClock(100000); + + seg.displayOn(); + seg.suppressLeadingZeroPlaces(0); + + Serial.println("displayTest()"); + seg.displayTest(100); + seg.displayOff(); + delay(1000); + seg.displayOn(); +} + +void loop() +{ + Serial.println("Int"); + seg.displayInt(9999); + delay(1000); + + Serial.println("Hex"); + seg.displayHex(0xABCF); + delay(1000); + + Serial.println("dim()"); + for (int i = 0; i < 16; i++) + { + seg.brightness(i); + delay(500); + } + for (int i = 15; i > 0; i--) + { + seg.brightness(i); + delay(500); + } + seg.brightness(2); + + Serial.println("displayClear()"); + seg.displayClear(); + delay(1000); + + Serial.println("displayTime()"); + seg.displayTime(13, 25); + for (int i = 50; i < 60; i++) + { + seg.displayTime(13, i); + delay(500); + seg.displayColon(true); + delay(500); + } + + Serial.println("float"); + seg.displayClear(); + delay(500); + seg.displayFloat(3.14159265); + delay(500); + seg.displayFloat(99999); + delay(500); + seg.displayFloat(9999); + delay(500); + seg.displayFloat(31.4159265); + delay(500); + seg.displayFloat(314.159265); + delay(500); + seg.displayFloat(3141.59265); + delay(500); + seg.displayFloat(0.314159265); + delay(500); + seg.displayFloat(0.0314159265); + delay(500); + seg.displayFloat(0.00314159265); + delay(500); + seg.displayFloat(0.000314159265); + delay(500); + + + Serial.println("Voltmeter"); + for (int i = 0; i < 100; i++) + { + float voltage = analogRead(A0) * 5.0 / 1023; + seg.displayFloat(voltage); + delay(100); + } + + Serial.println("blink()"); + for (uint8_t i = 0; i < 3; i++) + { + seg.blink(i); + delay(4000); + } + seg.blink(0); + + Serial.print("INT TEST:\t"); + start = millis(); + for (uint16_t counter = 0; counter < 9999; counter++) + { + seg.displayInt(counter); + } + stop = millis(); + Serial.println(stop - start); + + + Serial.print("HEX TEST:\t"); + start = millis(); + for (uint16_t counter = 0; counter < 0xFFFF; counter++) + { + seg.displayHex(counter); + } + stop = millis(); + Serial.println(stop - start); + + Serial.print("SUPRESS ZERO TEST:\t"); + for (uint8_t nlz = 0; nlz < 5; nlz++) + { + Serial.print(nlz); + seg.suppressLeadingZeroPlaces(nlz); + seg.displayInt(0); + delay(1000); + } + seg.suppressLeadingZeroPlaces(0); + Serial.println("\n -- DONE -- \n"); +} + + +// -- END OF FILE -- diff --git a/examples/demo3/demo3.ino b/examples/demo3/demo3.ino new file mode 100644 index 0000000..8e69120 --- /dev/null +++ b/examples/demo3/demo3.ino @@ -0,0 +1,148 @@ +// +// FILE: 4x7segmentI2C.ino +// AUTHOR: Rob Tillaart +// PURPOSE: demo 3 +// URL: http://www.adafruit.com/products/1002 +// URL: https://github.com/RobTillaart/HT16K33 + +#include "HT16K33.h" + +HT16K33 seg(0x70); + +uint32_t start; +uint32_t stop; + +uint8_t ar[4]; + +void setup() +{ + Serial.begin(115200); + Serial.println(__FILE__); + + seg.begin(); + Wire.setClock(100000); + + seg.displayOn(); + seg.suppressLeadingZeroPlaces(0); + + Serial.println("displayTest()"); + seg.displayTest(10); + seg.displayOff(); + delay(1000); + seg.displayOn(); + seg.displayColon(false); +} + +void loop() +{ + // comment tests you do not want to see + test_elsa(); + delay(100); + test_random(); + delay(100); + test_VULeft(); + delay(100); + test_VURight(); + delay(100); + test_VUStereo(); + delay(100); +} + +void test_elsa() +{ + ar[0] = 0x79; + ar[1] = 0x38; + ar[2] = 0x6D; + ar[3] = 0x77; + seg.displayRaw(ar); +} + +void test_random() +{ + for (uint8_t i = 0; i < 4; i++) + { + ar[i] = random(256); + } + seg.displayRaw(ar); +} + +void test_VULeft() +{ + int val = analogRead(A0); + val = val / 120; // 0..8 + seg.displayVULeft(val); +} + +void test_VURight() +{ + int val = analogRead(A0); + val = val / 120; // 0..8 + seg.displayVURight(val); +} + +void test_VUStereo() +{ + uint8_t left = analogRead(A0) / 240; // 0..4 + uint8_t right = analogRead(A1) / 240; // 0..4 + displayVUStereo(left, right); +} + +void displayVUStereo(uint8_t left, uint8_t right) +{ + switch (left) + { + case 0: + ar[0] = 0x00; + ar[1] = 0x00; + break; + case 1: + ar[0] = 0x00; + ar[1] = 0x06; + break; + case 2: + ar[0] = 0x00; + ar[1] = 0x36; + break; + case 3: + ar[0] = 0x06; + ar[1] = 0x36; + break; + case 4: + default: + ar[0] = 0x36; + ar[1] = 0x36; + break; + } + switch (right) + { + case 0: + ar[2] = 0x00; + ar[3] = 0x00; + break; + case 1: + ar[2] = 0x30; + ar[3] = 0x00; + break; + case 2: + ar[2] = 0x36; + ar[3] = 0x00; + break; + case 3: + ar[2] = 0x36; + ar[3] = 0x30; + break; + case 4: + default: + ar[2] = 0x36; + ar[3] = 0x36; + break; + } + seg.displayRaw(ar); + + // sort of heartbeat + static bool t = false; + seg.displayColon(t); + t = !t; +} + +// -- END OF FILE -- diff --git a/keywords.txt b/keywords.txt index e5c3424..6c4c25f 100644 --- a/keywords.txt +++ b/keywords.txt @@ -38,6 +38,8 @@ displayColon KEYWORD2 displayTest KEYWORD2 displayRaw KEYWORD2 +displayExtraLeds KEYWORD2 + displayVULeft KEYWORD2 displayVURight KEYWORD2 diff --git a/library.json b/library.json index 4d56676..df8b332 100644 --- a/library.json +++ b/library.json @@ -15,7 +15,7 @@ "type": "git", "url": "https://github.com/RobTillaart/HT16K33.git" }, - "version": "0.3.4", + "version": "0.3.5", "license": "MIT", "frameworks": "arduino", "platforms": "*", diff --git a/library.properties b/library.properties index 5b65f7e..722500b 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=HT16K33 -version=0.3.4 +version=0.3.5 author=Rob Tillaart maintainer=Rob Tillaart sentence=Arduino Library for HT16K33 I2C 4x7segment display