Skip to content

Commit

Permalink
fix #21 displayExtraLeds() (#22)
Browse files Browse the repository at this point in the history
* fix #21 displayExtraLeds()
  • Loading branch information
RobTillaart authored Sep 24, 2022
1 parent c4fc4ba commit bbd40fb
Show file tree
Hide file tree
Showing 8 changed files with 339 additions and 7 deletions.
16 changes: 15 additions & 1 deletion HT16K33.cpp
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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,
Expand All @@ -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"
Expand Down Expand Up @@ -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
Expand Down
12 changes: 10 additions & 2 deletions HT16K33.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -14,7 +14,7 @@
#include "Wire.h"


#define HT16K33_LIB_VERSION (F("0.3.4"))
#define HT16K33_LIB_VERSION (F("0.3.5"))


// Characters
Expand Down Expand Up @@ -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

Expand Down
21 changes: 19 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -139,16 +153,19 @@ 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()**
- **void setBlink()** and **uint8_t getBlink()**
- **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
Expand Down
143 changes: 143 additions & 0 deletions examples/demo2/demo2.ino
Original file line number Diff line number Diff line change
@@ -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 --
Loading

0 comments on commit bbd40fb

Please sign in to comment.