From 060386e0eb2ff6733f669c688a6098ec2656e802 Mon Sep 17 00:00:00 2001 From: "fourstix@gmail.com" Date: Thu, 30 Apr 2020 08:32:56 -0400 Subject: [PATCH 1/4] Added defineChar function and updated examples --- .../Example10_DefineChar.ino | 64 ++++ .../Example7_unkownChar.ino | 7 +- src/SparkFun_Alphanumeric_Display.cpp | 359 ++++++++---------- src/SparkFun_Alphanumeric_Display.h | 13 +- 4 files changed, 226 insertions(+), 217 deletions(-) create mode 100644 examples/Example10_DefineChar/Example10_DefineChar.ino diff --git a/examples/Example10_DefineChar/Example10_DefineChar.ino b/examples/Example10_DefineChar/Example10_DefineChar.ino new file mode 100644 index 0000000..c601dfa --- /dev/null +++ b/examples/Example10_DefineChar/Example10_DefineChar.ino @@ -0,0 +1,64 @@ +/************************************************************************************** + * This example redefines some characters of an alphanumeric display. + * + * Written by Gaston Williams + * April 30, 2020 + * + * Based on code written by + * Priyanka Makin @ SparkFun Electronics + * Original Creation Date: February 26, 2020 + * + * SparkFun labored with love to create this code. Feel like supporting open source hardware? + * Buy a board from SparkFun! https://www.sparkfun.com/products/16426 + * + * This code is beerware; if you see me (or any other SparkFun employee) at the + * local, and you've found our code helpful, please buy us a round! + * + * Hardware Connections: + * Attach Red Board to computer using micro-B USB cable. + * Attach Qwiic Alphanumeric board to Red Board using Qwiic cable. + * Don't close any of the address jumpers so that it defaults to address 0x70. + * + * Distributed as-is; no warranty is given. + *****************************************************************************************/ +#include +HT16K33 display; + +void setup() { + Serial.begin(115200); + Serial.println("Qwiic Alphanumeric examples"); + Wire.begin(); //Join I2C bus + + //check if displays will acknowledge + if (display.begin() == false) + { + Serial.println("Device did not acknowledge! Freezing."); + while(1); + } + Serial.println("Displays acknowledged."); + + //Just for demo purposes, show original characters before change + display.print("cafe"); + delay(500); + display.print("size"); + + + //Update a, e, f, s and z to new characters + //This change is not permanent, and lasts only for this program. + + //define 14 segment bits: nmlkjihgfedcba + display.defineChar('a', 0b01000001011000); + display.defineChar('e', 0b10000001011000); + display.defineChar('f', 0b01010101000000); + display.defineChar('s', 0b00100100001000); + display.defineChar('z', 0b10000001001000); +} + +void loop() +{ + //Show the new characters + delay(500); + display.print("cafe"); + delay(500); + display.print("size"); +} diff --git a/examples/Example7_unkownChar/Example7_unkownChar.ino b/examples/Example7_unkownChar/Example7_unkownChar.ino index 77918ed..50af555 100644 --- a/examples/Example7_unkownChar/Example7_unkownChar.ino +++ b/examples/Example7_unkownChar/Example7_unkownChar.ino @@ -3,9 +3,10 @@ * * Priyanka Makin @ SparkFun Electronics * Original Creation Date: March 13, 2020 + * Updated April 30, 2020 by Gaston Williams - changed exclamation to tab character * * SparkFun labored with love to create this code. Feel like supporting open source hardware? - * Buy a board from SparkFun! https://www.sparkfun.com/products/16391 + * Buy a board from SparkFun! LINK GOES HERE * * This code is Lemonadeware; if you see me (or any other SparkFun employee) at the * local, and you've found our code helpful, please buy us a round! @@ -18,7 +19,7 @@ ****************************************************************************************/ #include -#include //Click here to get the library: http://librarymanager/All#Alphanumeric_Display by SparkFun +#include //Click here to get the library: HT16K33 display; void setup() { @@ -34,7 +35,7 @@ void setup() { } Serial.println("Display acknowledged."); - display.print("!!!!"); + display.print("\t\t\t\t"); //tabs are not printable characters } void loop() diff --git a/src/SparkFun_Alphanumeric_Display.cpp b/src/SparkFun_Alphanumeric_Display.cpp index ea319a4..3013001 100644 --- a/src/SparkFun_Alphanumeric_Display.cpp +++ b/src/SparkFun_Alphanumeric_Display.cpp @@ -5,6 +5,8 @@ Priyanka Makin @ SparkFun Electronics Original Creation Date: February 25, 2020 https://github.com/sparkfun/SparkFun_Alphanumeric_Display_Arduino_Library +Updated April 30, 2020 by Gaston Williams to add defineChar function + Pickup a board here: https://sparkle.sparkfun.com/sparkle/storefront_products/16391 This file implements all functions of the HT16K33 class. Functions here range @@ -12,8 +14,8 @@ from printing to one or more Alphanumeric Displays, changing the display setting reading the RAM of the HT16K33. The Holtek HT16K33 seems to be susceptible to address changes intra-sketch. The ADR pins -are muxed with the ROW and COM drivers so as semgents are turned on/off that affect -the ADR1/ADR0 pins the address has been seen to change. The best way around this is +are muxed with the ROW and COM drivers so as semgents are turned on/off that affect +the ADR1/ADR0 pins the address has been seen to change. The best way around this is to do a isConnected check before updateRAM() is sent to the driver IC. Development environment specifics: @@ -318,37 +320,6 @@ bool HT16K33::setDisplayOnOff(uint8_t displayNumber, bool turnOnDisplay) return (writeRAM(lookUpDisplayAddress(displayNumber), dataToWrite)); } -//Turn on/off the entire display -bool HT16K33::displayOn() -{ - bool status = true; - - displayOnOff = ALPHA_DISPLAY_ON; - - for (uint8_t i = 0; i < numberOfDisplays; i++) - { - if (displayOnSingle(i) == false) - status = false; - } - - return status; -} - -bool HT16K33::displayOff() -{ - bool status = true; - - displayOnOff = ALPHA_DISPLAY_OFF; - - for (uint8_t i = 0; i < numberOfDisplays; i++) - { - if (displayOffSingle(i) == false) - status = false; - } - - return status; -} - bool HT16K33::decimalOnSingle(uint8_t displayNumber) { return setDecimalOnOff(displayNumber, true); @@ -362,52 +333,14 @@ bool HT16K33::decimalOffSingle(uint8_t displayNumber) bool HT16K33::setDecimalOnOff(uint8_t displayNumber, bool turnOnDecimal) { uint8_t adr = 0x03; - uint8_t dat; + uint8_t dat = 0x01; if (turnOnDecimal == true) - { decimalOnOff = ALPHA_DECIMAL_ON; - dat = 0x01; - } else - { decimalOnOff = ALPHA_DECIMAL_OFF; - dat = 0x00; - } - - displayRAM[adr + displayNumber * 16] = displayRAM[adr + displayNumber * 16] | dat; - updateDisplay(); -} - -//Turn on/off the entire display -bool HT16K33::decimalOn() -{ - bool status = true; - - decimalOnOff = ALPHA_DECIMAL_ON; - - for (uint8_t i = 0; i < numberOfDisplays; i++) - { - if (decimalOnSingle(i) == false) - status = false; - } - - Serial.println(status); - return status; -} - -bool HT16K33::decimalOff() -{ - bool status = true; - - decimalOnOff = ALPHA_DECIMAL_OFF; - for (uint8_t i = 0; i < numberOfDisplays; i++) - { - if (decimalOffSingle(i) == false) - status = false; - } - return status; + displayRAM[adr] = displayRAM[adr] | dat; } bool HT16K33::colonOnSingle(uint8_t displayNumber) @@ -423,48 +356,44 @@ bool HT16K33::colonOffSingle(uint8_t displayNumber) bool HT16K33::setColonOnOff(uint8_t displayNumber, bool turnOnColon) { uint8_t adr = 0x01; - uint8_t dat; + uint8_t dat = 0x01; - if (turnOnColon == true) - { + if (turnOnColon = true) colonOnOff = ALPHA_COLON_ON; - dat = 0x01; - } else - { colonOnOff = ALPHA_COLON_OFF; - dat = 0x00; - } - displayRAM[adr + displayNumber * 16] = displayRAM[adr + displayNumber * 16] | dat; - updateDisplay(); + displayRAM[adr] = displayRAM[adr] | dat; } -bool HT16K33::colonOn() +//Turn on/off the entire display +bool HT16K33::displayOn() { bool status = true; - colonOnOff = ALPHA_COLON_ON; + displayOnOff = ALPHA_DISPLAY_ON; for (uint8_t i = 0; i < numberOfDisplays; i++) { - if (colonOnSingle(i) == false) + if (displayOnSingle(i) == false) status = false; } + return status; } -bool HT16K33::colonOff() +bool HT16K33::displayOff() { bool status = true; - - colonOnOff = ALPHA_COLON_OFF; + + displayOnOff = ALPHA_DISPLAY_OFF; for (uint8_t i = 0; i < numberOfDisplays; i++) { - if (colonOffSingle(i) == false) + if (displayOffSingle(i) == false) status = false; } + return status; } @@ -527,136 +456,131 @@ void HT16K33::illuminateChar(uint16_t segmentsToTurnOn, uint8_t digit) } } -#define SFE_ALPHANUM_UNKNOWN_CHAR 89 +#define SFE_ALPHANUM_UNKNOWN_CHAR 95 //This is the lookup table of segments for various characters +static uint16_t alphanumeric_segs[96]{ + //nmlkjihgfedcba + 0b00000000000000, //' ' (space) + 0b00001000001000, //'!' - added to map + 0b00001000000010, //'"' - added to map + 0b1001101001110, //'#' + 0b1001101101101, //'$' + 0b10010000100100, //'%' + 0b110011011001, //'&' + 0b1000000000, //''' + 0b111001, //'(' + 0b1111, //')' + 0b11111010000000, //'*' + 0b1001101000000, //'+' + 0b10000000000000, //',' + 0b101000000, //'-' + 0b10, //'.' - DEBUG: need to test + 0b10010000000000, //'/' + 0b111111, //'0' + 0b10000000110, //'1' + 0b101011011, //'2' + 0b101001111, //'3' + 0b101100110, //'4' + 0b101101101, //'5' + 0b101111101, //'6' + 0b1010000000001, //'7' + 0b101111111, //'8' + 0b101100111, //'9' + 0b1, //':' - DEBUG: need to test + 0b10001000000000, //';' + 0b110000000000, //'<' + 0b101001000, //'=' + 0b10000010000000, //'>' + 0b01001000000000, //':' - Added to map + 0b10001000000000, //';' - Added to map + 0b101110111, //'A' + 0b1001100001111, //'B' + 0b111001, //'C' + 0b1001000001111, //'D' + 0b101111001, //'E' + 0b101110001, //'F' + 0b100111101, //'G' + 0b101110110, //'H' + 0b1001000001001, //'I' + 0b11110, //'J' + 0b110001110000, //'K' + 0b111000, //'L' + 0b10010110110, //'M' + 0b100010110110, //'N' + 0b111111, //'O' + 0b101110011, //'P' + 0b100000111111, //'Q' + 0b100101110011, //'R' + 0b110001101, //'S' + 0b1001000000001, //'T' + 0b111110, //'U' + 0b10010000110000, //'V' + 0b10100000110110, //'W' + 0b10110010000000, //'X' + 0b1010010000000, //'Y' + 0b10010000001001, //'Z' + 0b111001, //'[' + 0b100010000000, //'\' + 0b1111, //']' + 0b10100000000000, //'^' - Added to map + 0b1000, //'_' + 0b10000000, //'`' + 0b101011111, //'a' + 0b100001111000, //'b' + 0b101011000, //'c' + 0b10000100001110, //'d' + 0b1111001, //'e' + 0b1110001, //'f' + 0b110001111, //'g' + 0b101110100, //'h' + 0b1000000000000, //'i' + 0b1110, //'j' + 0b1111000000000, //'k' + 0b1001000000000, //'l' + 0b1000101010100, //'m' + 0b100001010000, //'n' + 0b101011100, //'o' + 0b10001110001, //'p' + 0b100101100011, //'q' + 0b1010000, //'r' + 0b110001101, //'s' + 0b1111000, //'t' + 0b11100, //'u' + 0b10000000010000, //'v' + 0b10100000010100, //'w' + 0b10110010000000, //'x' + 0b1100001110, //'y' + 0b10010000001001, //'z' + 0b10000011001001, //'{' + 0b1001000000000, //'|' + 0b110100001001, //'}' + 0b00000101010010, //'~' - Added to map + 0b11111111111111, //Unknown character (DEL or RUBOUT) +}; + +//Show a character on display void HT16K33::printChar(uint8_t displayChar, uint8_t digit) { - - static uint16_t alphanumeric_segs[90]{ - 0b00000000000000, //' ' (space) - - 0b1001101001110, //'#' - 0b1001101101101, //'$' - 0b10010000100100, //'%' - 0b110011011001, //'&' - 0b1000000000, //''' - 0b111001, //'(' - 0b1111, //')' - 0b11111010000000, //'*' - 0b1001101000000, //'+' - 0b10000000000000, //',' - 0b101000000, //'-' - 0b10, //'.' - DEBUG: need to test - 0b10010000000000, //'/' - 0b111111, //'0' - 0b10000000110, //'1' - 0b101011011, //'2' - 0b101001111, //'3' - 0b101100110, //'4' - 0b101101101, //'5' - 0b101111101, //'6' - 0b1010000000001, //'7' - 0b101111111, //'8' - 0b101100111, //'9' - 0b1, //':' - DEBUG: need to test - 0b10001000000000, //';' - 0b110000000000, //'<' - 0b101001000, //'=' - 0b10000010000000, //'>' - - 0b101110111, //'A' - 0b1001100001111, //'B' - 0b111001, //'C' - 0b1001000001111, //'D' - 0b101111001, //'E' - 0b101110001, //'F' - 0b100111101, //'G' - 0b101110110, //'H' - 0b1001000001001, //'I' - 0b11110, //'J' - 0b110001110000, //'K' - 0b111000, //'L' - 0b10010110110, //'M' - 0b100010110110, //'N' - 0b111111, //'O' - 0b101110011, //'P' - 0b100000111111, //'Q' - 0b100101110011, //'R' - 0b110001101, //'S' - 0b1001000000001, //'T' - 0b111110, //'U' - 0b10010000110000, //'V' - 0b10100000110110, //'W' - 0b10110010000000, //'X' - 0b1010010000000, //'Y' - 0b10010000001001, //'Z' - 0b111001, //'[' - 0b100010000000, //'\' - 0b1111, //']' - - 0b1000, //'_' - 0b10000000, //'`' - 0b101011111, //'a' - 0b100001111000, //'b' - 0b101011000, //'c' - 0b10000100001110, //'d' - 0b1111001, //'e' - 0b1110001, //'f' - 0b110001111, //'g' - 0b101110100, //'h' - 0b1000000000000, //'i' - 0b1110, //'j' - 0b1111000000000, //'k' - 0b1001000000000, //'l' - 0b1000101010100, //'m' - 0b100001010000, //'n' - 0b101011100, //'o' - 0b10001110001, //'p' - 0b100101100011, //'q' - 0b1010000, //'r' - 0b110001101, //'s' - 0b1111000, //'t' - 0b11100, //'u' - 0b10000000010000, //'v' - 0b10100000010100, //'w' - 0b10110010000000, //'x' - 0b1100001110, //'y' - 0b10010000001001, //'z' - 0b10000011001001, //'{' - 0b1001000000000, //'|' - 0b110100001001, //'}' - - 0b11111111111111, //Unknown character - }; + //moved alphanumeric_segs array outside of function uint16_t characterPosition = 65532; //space if (displayChar == ' ') characterPosition = 0; - //Symbols - else if (displayChar >= '#' && displayChar <= '>') - { - characterPosition = displayChar - '#' + 1; - } - //Upper case letters + symbols - else if (displayChar >= 'A' && displayChar <= ']') + //Printable Symbols + else if (displayChar >= '!' && displayChar <= '~') { - characterPosition = displayChar - 'A' + 1 + 28; - } - //Symbols + lower case letters - else - { - characterPosition = displayChar - '_' + 1 + 28 + 29; + characterPosition = displayChar - '!' + 1; } - uint8_t dispNum = digitPosition / 4; + //Take care of special characters - if (characterPosition == 12) //'.' - decimalOnSingle(dispNum); - if (characterPosition == 24) //':' - colonOnSingle(dispNum); + if (characterPosition == 14) //'.' + decimalOnSingle(0); + if (characterPosition == 26) //':' + colonOnSingle(0); if (characterPosition == 65532) //unknown character characterPosition = SFE_ALPHANUM_UNKNOWN_CHAR; @@ -667,8 +591,29 @@ void HT16K33::printChar(uint8_t displayChar, uint8_t digit) illuminateChar(alphanumeric_segs[characterPosition], digit); } + +//Update the lookup table of segments for a particular character +bool HT16K33::defineChar(uint8_t displayChar, uint16_t segmentsToTurnOn) +{ + bool result = false; + + //Check to see if character is within range of displayable ASCII characters + if (displayChar >= '!' && displayChar <= '~') + { + //Get the index of character in map and update its 14-bit segment value + uint16_t characterPosition = displayChar - '!' + 1; + + //Mask the input segment value to 14 bits only + alphanumeric_segs[characterPosition] = (segmentsToTurnOn & 0x3FFF); + + //We're all good + result = true; + } + return result; +} + /* - * Write a byte to the display. + * Write a byte to the display.1 * Required for Print. */ size_t HT16K33::write(uint8_t b) diff --git a/src/SparkFun_Alphanumeric_Display.h b/src/SparkFun_Alphanumeric_Display.h index 117f6c6..044446d 100644 --- a/src/SparkFun_Alphanumeric_Display.h +++ b/src/SparkFun_Alphanumeric_Display.h @@ -5,6 +5,8 @@ Priyanka Makin @ SparkFun Electronics Original Creation Date: July 25, 2019 https://github.com/sparkfun/SparkFun_Alphanumeric_Display_Arduino_Library +Updated April 30, 2020 by Gaston Williams to add defineChar function + Pickup a board here: https://sparkle.sparkfun.com/sparkle/storefront_products/16391 This file prototypes the HT16K33 class, implemented in SparkFun_Alphanumeric_Display.cpp. @@ -26,7 +28,7 @@ Distributed as-is; no warranty is given. #include #define DEFAULT_ADDRESS 0x70 //Default I2C address when A0, A1 are floating -// #define DEV_ID 0x12 //Device ID that I just made up +#define DEV_ID 0x12 //Device ID that I just made up #define DEFAULT_NOTHING_ATTACHED 0xFF typedef enum @@ -91,7 +93,7 @@ class HT16K33 : public Print TwoWire &wirePort = Wire); // Sets the address of the device and opens the Wire port for communication bool isConnected(uint8_t displayNumber); bool initialize(); - // bool checkDeviceID(uint8_t displayNumber); + bool checkDeviceID(uint8_t displayNumber); uint8_t lookUpDisplayAddress(uint8_t displayNumber); //Display configuration functions @@ -118,16 +120,13 @@ class HT16K33 : public Print void illuminateChar(uint16_t disp, uint8_t digit); void printChar(uint8_t displayChar, uint8_t digit); bool updateDisplay(); + //Define Character Segment Map + bool defineChar(uint8_t displayChar, uint16_t segmentsToTurnOn); //Colon and decimal - bool decimalOn(); - bool decimalOff(); bool decimalOnSingle(uint8_t displayNumber); bool decimalOffSingle(uint8_t displayNumber); bool setDecimalOnOff(uint8_t displayNumber, bool turnOnDecimal); - - bool colonOn(); - bool colonOff(); bool colonOnSingle(uint8_t displayNumber); bool colonOffSingle(uint8_t displayNumber); bool setColonOnOff(uint8_t displayNumber, bool turnOnColon); From fc53fd423843b3368d27d453663640f640bf0b7c Mon Sep 17 00:00:00 2001 From: "fourstix@gmail.com" Date: Fri, 1 May 2020 13:40:21 -0400 Subject: [PATCH 2/4] Revert changes back to original code and redo updates --- .../Example10_DefineChar.ino | 64 ---- .../Example7_unkownChar.ino | 7 +- src/SparkFun_Alphanumeric_Display.cpp | 359 ++++++++++-------- src/SparkFun_Alphanumeric_Display.h | 13 +- 4 files changed, 217 insertions(+), 226 deletions(-) delete mode 100644 examples/Example10_DefineChar/Example10_DefineChar.ino diff --git a/examples/Example10_DefineChar/Example10_DefineChar.ino b/examples/Example10_DefineChar/Example10_DefineChar.ino deleted file mode 100644 index c601dfa..0000000 --- a/examples/Example10_DefineChar/Example10_DefineChar.ino +++ /dev/null @@ -1,64 +0,0 @@ -/************************************************************************************** - * This example redefines some characters of an alphanumeric display. - * - * Written by Gaston Williams - * April 30, 2020 - * - * Based on code written by - * Priyanka Makin @ SparkFun Electronics - * Original Creation Date: February 26, 2020 - * - * SparkFun labored with love to create this code. Feel like supporting open source hardware? - * Buy a board from SparkFun! https://www.sparkfun.com/products/16426 - * - * This code is beerware; if you see me (or any other SparkFun employee) at the - * local, and you've found our code helpful, please buy us a round! - * - * Hardware Connections: - * Attach Red Board to computer using micro-B USB cable. - * Attach Qwiic Alphanumeric board to Red Board using Qwiic cable. - * Don't close any of the address jumpers so that it defaults to address 0x70. - * - * Distributed as-is; no warranty is given. - *****************************************************************************************/ -#include -HT16K33 display; - -void setup() { - Serial.begin(115200); - Serial.println("Qwiic Alphanumeric examples"); - Wire.begin(); //Join I2C bus - - //check if displays will acknowledge - if (display.begin() == false) - { - Serial.println("Device did not acknowledge! Freezing."); - while(1); - } - Serial.println("Displays acknowledged."); - - //Just for demo purposes, show original characters before change - display.print("cafe"); - delay(500); - display.print("size"); - - - //Update a, e, f, s and z to new characters - //This change is not permanent, and lasts only for this program. - - //define 14 segment bits: nmlkjihgfedcba - display.defineChar('a', 0b01000001011000); - display.defineChar('e', 0b10000001011000); - display.defineChar('f', 0b01010101000000); - display.defineChar('s', 0b00100100001000); - display.defineChar('z', 0b10000001001000); -} - -void loop() -{ - //Show the new characters - delay(500); - display.print("cafe"); - delay(500); - display.print("size"); -} diff --git a/examples/Example7_unkownChar/Example7_unkownChar.ino b/examples/Example7_unkownChar/Example7_unkownChar.ino index 50af555..77918ed 100644 --- a/examples/Example7_unkownChar/Example7_unkownChar.ino +++ b/examples/Example7_unkownChar/Example7_unkownChar.ino @@ -3,10 +3,9 @@ * * Priyanka Makin @ SparkFun Electronics * Original Creation Date: March 13, 2020 - * Updated April 30, 2020 by Gaston Williams - changed exclamation to tab character * * SparkFun labored with love to create this code. Feel like supporting open source hardware? - * Buy a board from SparkFun! LINK GOES HERE + * Buy a board from SparkFun! https://www.sparkfun.com/products/16391 * * This code is Lemonadeware; if you see me (or any other SparkFun employee) at the * local, and you've found our code helpful, please buy us a round! @@ -19,7 +18,7 @@ ****************************************************************************************/ #include -#include //Click here to get the library: +#include //Click here to get the library: http://librarymanager/All#Alphanumeric_Display by SparkFun HT16K33 display; void setup() { @@ -35,7 +34,7 @@ void setup() { } Serial.println("Display acknowledged."); - display.print("\t\t\t\t"); //tabs are not printable characters + display.print("!!!!"); } void loop() diff --git a/src/SparkFun_Alphanumeric_Display.cpp b/src/SparkFun_Alphanumeric_Display.cpp index 3013001..ea319a4 100644 --- a/src/SparkFun_Alphanumeric_Display.cpp +++ b/src/SparkFun_Alphanumeric_Display.cpp @@ -5,8 +5,6 @@ Priyanka Makin @ SparkFun Electronics Original Creation Date: February 25, 2020 https://github.com/sparkfun/SparkFun_Alphanumeric_Display_Arduino_Library -Updated April 30, 2020 by Gaston Williams to add defineChar function - Pickup a board here: https://sparkle.sparkfun.com/sparkle/storefront_products/16391 This file implements all functions of the HT16K33 class. Functions here range @@ -14,8 +12,8 @@ from printing to one or more Alphanumeric Displays, changing the display setting reading the RAM of the HT16K33. The Holtek HT16K33 seems to be susceptible to address changes intra-sketch. The ADR pins -are muxed with the ROW and COM drivers so as semgents are turned on/off that affect -the ADR1/ADR0 pins the address has been seen to change. The best way around this is +are muxed with the ROW and COM drivers so as semgents are turned on/off that affect +the ADR1/ADR0 pins the address has been seen to change. The best way around this is to do a isConnected check before updateRAM() is sent to the driver IC. Development environment specifics: @@ -320,6 +318,37 @@ bool HT16K33::setDisplayOnOff(uint8_t displayNumber, bool turnOnDisplay) return (writeRAM(lookUpDisplayAddress(displayNumber), dataToWrite)); } +//Turn on/off the entire display +bool HT16K33::displayOn() +{ + bool status = true; + + displayOnOff = ALPHA_DISPLAY_ON; + + for (uint8_t i = 0; i < numberOfDisplays; i++) + { + if (displayOnSingle(i) == false) + status = false; + } + + return status; +} + +bool HT16K33::displayOff() +{ + bool status = true; + + displayOnOff = ALPHA_DISPLAY_OFF; + + for (uint8_t i = 0; i < numberOfDisplays; i++) + { + if (displayOffSingle(i) == false) + status = false; + } + + return status; +} + bool HT16K33::decimalOnSingle(uint8_t displayNumber) { return setDecimalOnOff(displayNumber, true); @@ -333,14 +362,52 @@ bool HT16K33::decimalOffSingle(uint8_t displayNumber) bool HT16K33::setDecimalOnOff(uint8_t displayNumber, bool turnOnDecimal) { uint8_t adr = 0x03; - uint8_t dat = 0x01; + uint8_t dat; if (turnOnDecimal == true) + { decimalOnOff = ALPHA_DECIMAL_ON; + dat = 0x01; + } else + { decimalOnOff = ALPHA_DECIMAL_OFF; + dat = 0x00; + } - displayRAM[adr] = displayRAM[adr] | dat; + displayRAM[adr + displayNumber * 16] = displayRAM[adr + displayNumber * 16] | dat; + updateDisplay(); +} + +//Turn on/off the entire display +bool HT16K33::decimalOn() +{ + bool status = true; + + decimalOnOff = ALPHA_DECIMAL_ON; + + for (uint8_t i = 0; i < numberOfDisplays; i++) + { + if (decimalOnSingle(i) == false) + status = false; + } + + Serial.println(status); + return status; +} + +bool HT16K33::decimalOff() +{ + bool status = true; + + decimalOnOff = ALPHA_DECIMAL_OFF; + + for (uint8_t i = 0; i < numberOfDisplays; i++) + { + if (decimalOffSingle(i) == false) + status = false; + } + return status; } bool HT16K33::colonOnSingle(uint8_t displayNumber) @@ -356,44 +423,48 @@ bool HT16K33::colonOffSingle(uint8_t displayNumber) bool HT16K33::setColonOnOff(uint8_t displayNumber, bool turnOnColon) { uint8_t adr = 0x01; - uint8_t dat = 0x01; + uint8_t dat; - if (turnOnColon = true) + if (turnOnColon == true) + { colonOnOff = ALPHA_COLON_ON; + dat = 0x01; + } else + { colonOnOff = ALPHA_COLON_OFF; + dat = 0x00; + } - displayRAM[adr] = displayRAM[adr] | dat; + displayRAM[adr + displayNumber * 16] = displayRAM[adr + displayNumber * 16] | dat; + updateDisplay(); } -//Turn on/off the entire display -bool HT16K33::displayOn() +bool HT16K33::colonOn() { bool status = true; - displayOnOff = ALPHA_DISPLAY_ON; + colonOnOff = ALPHA_COLON_ON; for (uint8_t i = 0; i < numberOfDisplays; i++) { - if (displayOnSingle(i) == false) + if (colonOnSingle(i) == false) status = false; } - return status; } -bool HT16K33::displayOff() +bool HT16K33::colonOff() { bool status = true; - - displayOnOff = ALPHA_DISPLAY_OFF; + + colonOnOff = ALPHA_COLON_OFF; for (uint8_t i = 0; i < numberOfDisplays; i++) { - if (displayOffSingle(i) == false) + if (colonOffSingle(i) == false) status = false; } - return status; } @@ -456,131 +527,136 @@ void HT16K33::illuminateChar(uint16_t segmentsToTurnOn, uint8_t digit) } } -#define SFE_ALPHANUM_UNKNOWN_CHAR 95 +#define SFE_ALPHANUM_UNKNOWN_CHAR 89 //This is the lookup table of segments for various characters -static uint16_t alphanumeric_segs[96]{ - //nmlkjihgfedcba - 0b00000000000000, //' ' (space) - 0b00001000001000, //'!' - added to map - 0b00001000000010, //'"' - added to map - 0b1001101001110, //'#' - 0b1001101101101, //'$' - 0b10010000100100, //'%' - 0b110011011001, //'&' - 0b1000000000, //''' - 0b111001, //'(' - 0b1111, //')' - 0b11111010000000, //'*' - 0b1001101000000, //'+' - 0b10000000000000, //',' - 0b101000000, //'-' - 0b10, //'.' - DEBUG: need to test - 0b10010000000000, //'/' - 0b111111, //'0' - 0b10000000110, //'1' - 0b101011011, //'2' - 0b101001111, //'3' - 0b101100110, //'4' - 0b101101101, //'5' - 0b101111101, //'6' - 0b1010000000001, //'7' - 0b101111111, //'8' - 0b101100111, //'9' - 0b1, //':' - DEBUG: need to test - 0b10001000000000, //';' - 0b110000000000, //'<' - 0b101001000, //'=' - 0b10000010000000, //'>' - 0b01001000000000, //':' - Added to map - 0b10001000000000, //';' - Added to map - 0b101110111, //'A' - 0b1001100001111, //'B' - 0b111001, //'C' - 0b1001000001111, //'D' - 0b101111001, //'E' - 0b101110001, //'F' - 0b100111101, //'G' - 0b101110110, //'H' - 0b1001000001001, //'I' - 0b11110, //'J' - 0b110001110000, //'K' - 0b111000, //'L' - 0b10010110110, //'M' - 0b100010110110, //'N' - 0b111111, //'O' - 0b101110011, //'P' - 0b100000111111, //'Q' - 0b100101110011, //'R' - 0b110001101, //'S' - 0b1001000000001, //'T' - 0b111110, //'U' - 0b10010000110000, //'V' - 0b10100000110110, //'W' - 0b10110010000000, //'X' - 0b1010010000000, //'Y' - 0b10010000001001, //'Z' - 0b111001, //'[' - 0b100010000000, //'\' - 0b1111, //']' - 0b10100000000000, //'^' - Added to map - 0b1000, //'_' - 0b10000000, //'`' - 0b101011111, //'a' - 0b100001111000, //'b' - 0b101011000, //'c' - 0b10000100001110, //'d' - 0b1111001, //'e' - 0b1110001, //'f' - 0b110001111, //'g' - 0b101110100, //'h' - 0b1000000000000, //'i' - 0b1110, //'j' - 0b1111000000000, //'k' - 0b1001000000000, //'l' - 0b1000101010100, //'m' - 0b100001010000, //'n' - 0b101011100, //'o' - 0b10001110001, //'p' - 0b100101100011, //'q' - 0b1010000, //'r' - 0b110001101, //'s' - 0b1111000, //'t' - 0b11100, //'u' - 0b10000000010000, //'v' - 0b10100000010100, //'w' - 0b10110010000000, //'x' - 0b1100001110, //'y' - 0b10010000001001, //'z' - 0b10000011001001, //'{' - 0b1001000000000, //'|' - 0b110100001001, //'}' - 0b00000101010010, //'~' - Added to map - 0b11111111111111, //Unknown character (DEL or RUBOUT) -}; - -//Show a character on display void HT16K33::printChar(uint8_t displayChar, uint8_t digit) { - //moved alphanumeric_segs array outside of function + + static uint16_t alphanumeric_segs[90]{ + 0b00000000000000, //' ' (space) + + 0b1001101001110, //'#' + 0b1001101101101, //'$' + 0b10010000100100, //'%' + 0b110011011001, //'&' + 0b1000000000, //''' + 0b111001, //'(' + 0b1111, //')' + 0b11111010000000, //'*' + 0b1001101000000, //'+' + 0b10000000000000, //',' + 0b101000000, //'-' + 0b10, //'.' - DEBUG: need to test + 0b10010000000000, //'/' + 0b111111, //'0' + 0b10000000110, //'1' + 0b101011011, //'2' + 0b101001111, //'3' + 0b101100110, //'4' + 0b101101101, //'5' + 0b101111101, //'6' + 0b1010000000001, //'7' + 0b101111111, //'8' + 0b101100111, //'9' + 0b1, //':' - DEBUG: need to test + 0b10001000000000, //';' + 0b110000000000, //'<' + 0b101001000, //'=' + 0b10000010000000, //'>' + + 0b101110111, //'A' + 0b1001100001111, //'B' + 0b111001, //'C' + 0b1001000001111, //'D' + 0b101111001, //'E' + 0b101110001, //'F' + 0b100111101, //'G' + 0b101110110, //'H' + 0b1001000001001, //'I' + 0b11110, //'J' + 0b110001110000, //'K' + 0b111000, //'L' + 0b10010110110, //'M' + 0b100010110110, //'N' + 0b111111, //'O' + 0b101110011, //'P' + 0b100000111111, //'Q' + 0b100101110011, //'R' + 0b110001101, //'S' + 0b1001000000001, //'T' + 0b111110, //'U' + 0b10010000110000, //'V' + 0b10100000110110, //'W' + 0b10110010000000, //'X' + 0b1010010000000, //'Y' + 0b10010000001001, //'Z' + 0b111001, //'[' + 0b100010000000, //'\' + 0b1111, //']' + + 0b1000, //'_' + 0b10000000, //'`' + 0b101011111, //'a' + 0b100001111000, //'b' + 0b101011000, //'c' + 0b10000100001110, //'d' + 0b1111001, //'e' + 0b1110001, //'f' + 0b110001111, //'g' + 0b101110100, //'h' + 0b1000000000000, //'i' + 0b1110, //'j' + 0b1111000000000, //'k' + 0b1001000000000, //'l' + 0b1000101010100, //'m' + 0b100001010000, //'n' + 0b101011100, //'o' + 0b10001110001, //'p' + 0b100101100011, //'q' + 0b1010000, //'r' + 0b110001101, //'s' + 0b1111000, //'t' + 0b11100, //'u' + 0b10000000010000, //'v' + 0b10100000010100, //'w' + 0b10110010000000, //'x' + 0b1100001110, //'y' + 0b10010000001001, //'z' + 0b10000011001001, //'{' + 0b1001000000000, //'|' + 0b110100001001, //'}' + + 0b11111111111111, //Unknown character + }; uint16_t characterPosition = 65532; //space if (displayChar == ' ') characterPosition = 0; - //Printable Symbols - else if (displayChar >= '!' && displayChar <= '~') + //Symbols + else if (displayChar >= '#' && displayChar <= '>') { - characterPosition = displayChar - '!' + 1; + characterPosition = displayChar - '#' + 1; + } + //Upper case letters + symbols + else if (displayChar >= 'A' && displayChar <= ']') + { + characterPosition = displayChar - 'A' + 1 + 28; + } + //Symbols + lower case letters + else + { + characterPosition = displayChar - '_' + 1 + 28 + 29; } - + uint8_t dispNum = digitPosition / 4; //Take care of special characters - if (characterPosition == 14) //'.' - decimalOnSingle(0); - if (characterPosition == 26) //':' - colonOnSingle(0); + if (characterPosition == 12) //'.' + decimalOnSingle(dispNum); + if (characterPosition == 24) //':' + colonOnSingle(dispNum); if (characterPosition == 65532) //unknown character characterPosition = SFE_ALPHANUM_UNKNOWN_CHAR; @@ -591,29 +667,8 @@ void HT16K33::printChar(uint8_t displayChar, uint8_t digit) illuminateChar(alphanumeric_segs[characterPosition], digit); } - -//Update the lookup table of segments for a particular character -bool HT16K33::defineChar(uint8_t displayChar, uint16_t segmentsToTurnOn) -{ - bool result = false; - - //Check to see if character is within range of displayable ASCII characters - if (displayChar >= '!' && displayChar <= '~') - { - //Get the index of character in map and update its 14-bit segment value - uint16_t characterPosition = displayChar - '!' + 1; - - //Mask the input segment value to 14 bits only - alphanumeric_segs[characterPosition] = (segmentsToTurnOn & 0x3FFF); - - //We're all good - result = true; - } - return result; -} - /* - * Write a byte to the display.1 + * Write a byte to the display. * Required for Print. */ size_t HT16K33::write(uint8_t b) diff --git a/src/SparkFun_Alphanumeric_Display.h b/src/SparkFun_Alphanumeric_Display.h index 044446d..117f6c6 100644 --- a/src/SparkFun_Alphanumeric_Display.h +++ b/src/SparkFun_Alphanumeric_Display.h @@ -5,8 +5,6 @@ Priyanka Makin @ SparkFun Electronics Original Creation Date: July 25, 2019 https://github.com/sparkfun/SparkFun_Alphanumeric_Display_Arduino_Library -Updated April 30, 2020 by Gaston Williams to add defineChar function - Pickup a board here: https://sparkle.sparkfun.com/sparkle/storefront_products/16391 This file prototypes the HT16K33 class, implemented in SparkFun_Alphanumeric_Display.cpp. @@ -28,7 +26,7 @@ Distributed as-is; no warranty is given. #include #define DEFAULT_ADDRESS 0x70 //Default I2C address when A0, A1 are floating -#define DEV_ID 0x12 //Device ID that I just made up +// #define DEV_ID 0x12 //Device ID that I just made up #define DEFAULT_NOTHING_ATTACHED 0xFF typedef enum @@ -93,7 +91,7 @@ class HT16K33 : public Print TwoWire &wirePort = Wire); // Sets the address of the device and opens the Wire port for communication bool isConnected(uint8_t displayNumber); bool initialize(); - bool checkDeviceID(uint8_t displayNumber); + // bool checkDeviceID(uint8_t displayNumber); uint8_t lookUpDisplayAddress(uint8_t displayNumber); //Display configuration functions @@ -120,13 +118,16 @@ class HT16K33 : public Print void illuminateChar(uint16_t disp, uint8_t digit); void printChar(uint8_t displayChar, uint8_t digit); bool updateDisplay(); - //Define Character Segment Map - bool defineChar(uint8_t displayChar, uint16_t segmentsToTurnOn); //Colon and decimal + bool decimalOn(); + bool decimalOff(); bool decimalOnSingle(uint8_t displayNumber); bool decimalOffSingle(uint8_t displayNumber); bool setDecimalOnOff(uint8_t displayNumber, bool turnOnDecimal); + + bool colonOn(); + bool colonOff(); bool colonOnSingle(uint8_t displayNumber); bool colonOffSingle(uint8_t displayNumber); bool setColonOnOff(uint8_t displayNumber, bool turnOnColon); From 144872bcf8bf359afff60aef775287c30b5e7cc8 Mon Sep 17 00:00:00 2001 From: "fourstix@gmail.com" Date: Fri, 1 May 2020 14:13:49 -0400 Subject: [PATCH 3/4] Updated files with change, using a branch --- .../Example10_DefineChar.ino | 64 +++++++++++++++++++ .../Example7_unkownChar.ino | 3 +- 2 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 examples/Example10_DefineChar/Example10_DefineChar.ino diff --git a/examples/Example10_DefineChar/Example10_DefineChar.ino b/examples/Example10_DefineChar/Example10_DefineChar.ino new file mode 100644 index 0000000..c601dfa --- /dev/null +++ b/examples/Example10_DefineChar/Example10_DefineChar.ino @@ -0,0 +1,64 @@ +/************************************************************************************** + * This example redefines some characters of an alphanumeric display. + * + * Written by Gaston Williams + * April 30, 2020 + * + * Based on code written by + * Priyanka Makin @ SparkFun Electronics + * Original Creation Date: February 26, 2020 + * + * SparkFun labored with love to create this code. Feel like supporting open source hardware? + * Buy a board from SparkFun! https://www.sparkfun.com/products/16426 + * + * This code is beerware; if you see me (or any other SparkFun employee) at the + * local, and you've found our code helpful, please buy us a round! + * + * Hardware Connections: + * Attach Red Board to computer using micro-B USB cable. + * Attach Qwiic Alphanumeric board to Red Board using Qwiic cable. + * Don't close any of the address jumpers so that it defaults to address 0x70. + * + * Distributed as-is; no warranty is given. + *****************************************************************************************/ +#include +HT16K33 display; + +void setup() { + Serial.begin(115200); + Serial.println("Qwiic Alphanumeric examples"); + Wire.begin(); //Join I2C bus + + //check if displays will acknowledge + if (display.begin() == false) + { + Serial.println("Device did not acknowledge! Freezing."); + while(1); + } + Serial.println("Displays acknowledged."); + + //Just for demo purposes, show original characters before change + display.print("cafe"); + delay(500); + display.print("size"); + + + //Update a, e, f, s and z to new characters + //This change is not permanent, and lasts only for this program. + + //define 14 segment bits: nmlkjihgfedcba + display.defineChar('a', 0b01000001011000); + display.defineChar('e', 0b10000001011000); + display.defineChar('f', 0b01010101000000); + display.defineChar('s', 0b00100100001000); + display.defineChar('z', 0b10000001001000); +} + +void loop() +{ + //Show the new characters + delay(500); + display.print("cafe"); + delay(500); + display.print("size"); +} diff --git a/examples/Example7_unkownChar/Example7_unkownChar.ino b/examples/Example7_unkownChar/Example7_unkownChar.ino index 77918ed..0d74022 100644 --- a/examples/Example7_unkownChar/Example7_unkownChar.ino +++ b/examples/Example7_unkownChar/Example7_unkownChar.ino @@ -3,6 +3,7 @@ * * Priyanka Makin @ SparkFun Electronics * Original Creation Date: March 13, 2020 + * Updated April 30, 2020 by Gaston Williams - changed exclamation to tab character * * SparkFun labored with love to create this code. Feel like supporting open source hardware? * Buy a board from SparkFun! https://www.sparkfun.com/products/16391 @@ -34,7 +35,7 @@ void setup() { } Serial.println("Display acknowledged."); - display.print("!!!!"); + display.print("\t\t\t\t"); //tabs are not printable characters } void loop() From 6c93df57be440eb683f90efd8bcd14d861b99782 Mon Sep 17 00:00:00 2001 From: "fourstix@gmail.com" Date: Fri, 1 May 2020 14:16:10 -0400 Subject: [PATCH 4/4] Updated src files with change, using a branch --- src/SparkFun_Alphanumeric_Display.cpp | 246 ++++++++++++++------------ src/SparkFun_Alphanumeric_Display.h | 5 + 2 files changed, 136 insertions(+), 115 deletions(-) diff --git a/src/SparkFun_Alphanumeric_Display.cpp b/src/SparkFun_Alphanumeric_Display.cpp index ea319a4..2623e42 100644 --- a/src/SparkFun_Alphanumeric_Display.cpp +++ b/src/SparkFun_Alphanumeric_Display.cpp @@ -5,6 +5,8 @@ Priyanka Makin @ SparkFun Electronics Original Creation Date: February 25, 2020 https://github.com/sparkfun/SparkFun_Alphanumeric_Display_Arduino_Library +Updated April 30, 2020 by Gaston Williams to add defineChar function + Pickup a board here: https://sparkle.sparkfun.com/sparkle/storefront_products/16391 This file implements all functions of the HT16K33 class. Functions here range @@ -12,8 +14,8 @@ from printing to one or more Alphanumeric Displays, changing the display setting reading the RAM of the HT16K33. The Holtek HT16K33 seems to be susceptible to address changes intra-sketch. The ADR pins -are muxed with the ROW and COM drivers so as semgents are turned on/off that affect -the ADR1/ADR0 pins the address has been seen to change. The best way around this is +are muxed with the ROW and COM drivers so as semgents are turned on/off that affect +the ADR1/ADR0 pins the address has been seen to change. The best way around this is to do a isConnected check before updateRAM() is sent to the driver IC. Development environment specifics: @@ -457,7 +459,7 @@ bool HT16K33::colonOn() bool HT16K33::colonOff() { bool status = true; - + colonOnOff = ALPHA_COLON_OFF; for (uint8_t i = 0; i < numberOfDisplays; i++) @@ -527,128 +529,122 @@ void HT16K33::illuminateChar(uint16_t segmentsToTurnOn, uint8_t digit) } } -#define SFE_ALPHANUM_UNKNOWN_CHAR 89 +#define SFE_ALPHANUM_UNKNOWN_CHAR 95 //This is the lookup table of segments for various characters +static uint16_t alphanumeric_segs[96]{ + //nmlkjihgfedcba + 0b00000000000000, //' ' (space) + 0b00001000001000, //'!' - added to map + 0b00001000000010, //'"' - added to map + 0b1001101001110, //'#' + 0b1001101101101, //'$' + 0b10010000100100, //'%' + 0b110011011001, //'&' + 0b1000000000, //''' + 0b111001, //'(' + 0b1111, //')' + 0b11111010000000, //'*' + 0b1001101000000, //'+' + 0b10000000000000, //',' + 0b101000000, //'-' + 0b10, //'.' - DEBUG: need to test + 0b10010000000000, //'/' + 0b111111, //'0' + 0b10000000110, //'1' + 0b101011011, //'2' + 0b101001111, //'3' + 0b101100110, //'4' + 0b101101101, //'5' + 0b101111101, //'6' + 0b1010000000001, //'7' + 0b101111111, //'8' + 0b101100111, //'9' + 0b1, //':' - DEBUG: need to test + 0b10001000000000, //';' + 0b110000000000, //'<' + 0b101001000, //'=' + 0b10000010000000, //'>' + 0b01001000000000, //':' - Added to map + 0b10001000000000, //';' - Added to map + 0b101110111, //'A' + 0b1001100001111, //'B' + 0b111001, //'C' + 0b1001000001111, //'D' + 0b101111001, //'E' + 0b101110001, //'F' + 0b100111101, //'G' + 0b101110110, //'H' + 0b1001000001001, //'I' + 0b11110, //'J' + 0b110001110000, //'K' + 0b111000, //'L' + 0b10010110110, //'M' + 0b100010110110, //'N' + 0b111111, //'O' + 0b101110011, //'P' + 0b100000111111, //'Q' + 0b100101110011, //'R' + 0b110001101, //'S' + 0b1001000000001, //'T' + 0b111110, //'U' + 0b10010000110000, //'V' + 0b10100000110110, //'W' + 0b10110010000000, //'X' + 0b1010010000000, //'Y' + 0b10010000001001, //'Z' + 0b111001, //'[' + 0b100010000000, //'\' + 0b1111, //']' + 0b10100000000000, //'^' - Added to map + 0b1000, //'_' + 0b10000000, //'`' + 0b101011111, //'a' + 0b100001111000, //'b' + 0b101011000, //'c' + 0b10000100001110, //'d' + 0b1111001, //'e' + 0b1110001, //'f' + 0b110001111, //'g' + 0b101110100, //'h' + 0b1000000000000, //'i' + 0b1110, //'j' + 0b1111000000000, //'k' + 0b1001000000000, //'l' + 0b1000101010100, //'m' + 0b100001010000, //'n' + 0b101011100, //'o' + 0b10001110001, //'p' + 0b100101100011, //'q' + 0b1010000, //'r' + 0b110001101, //'s' + 0b1111000, //'t' + 0b11100, //'u' + 0b10000000010000, //'v' + 0b10100000010100, //'w' + 0b10110010000000, //'x' + 0b1100001110, //'y' + 0b10010000001001, //'z' + 0b10000011001001, //'{' + 0b1001000000000, //'|' + 0b110100001001, //'}' + 0b00000101010010, //'~' - Added to map + 0b11111111111111, //Unknown character (DEL or RUBOUT) +}; + +//Show a character on display void HT16K33::printChar(uint8_t displayChar, uint8_t digit) { - - static uint16_t alphanumeric_segs[90]{ - 0b00000000000000, //' ' (space) - - 0b1001101001110, //'#' - 0b1001101101101, //'$' - 0b10010000100100, //'%' - 0b110011011001, //'&' - 0b1000000000, //''' - 0b111001, //'(' - 0b1111, //')' - 0b11111010000000, //'*' - 0b1001101000000, //'+' - 0b10000000000000, //',' - 0b101000000, //'-' - 0b10, //'.' - DEBUG: need to test - 0b10010000000000, //'/' - 0b111111, //'0' - 0b10000000110, //'1' - 0b101011011, //'2' - 0b101001111, //'3' - 0b101100110, //'4' - 0b101101101, //'5' - 0b101111101, //'6' - 0b1010000000001, //'7' - 0b101111111, //'8' - 0b101100111, //'9' - 0b1, //':' - DEBUG: need to test - 0b10001000000000, //';' - 0b110000000000, //'<' - 0b101001000, //'=' - 0b10000010000000, //'>' - - 0b101110111, //'A' - 0b1001100001111, //'B' - 0b111001, //'C' - 0b1001000001111, //'D' - 0b101111001, //'E' - 0b101110001, //'F' - 0b100111101, //'G' - 0b101110110, //'H' - 0b1001000001001, //'I' - 0b11110, //'J' - 0b110001110000, //'K' - 0b111000, //'L' - 0b10010110110, //'M' - 0b100010110110, //'N' - 0b111111, //'O' - 0b101110011, //'P' - 0b100000111111, //'Q' - 0b100101110011, //'R' - 0b110001101, //'S' - 0b1001000000001, //'T' - 0b111110, //'U' - 0b10010000110000, //'V' - 0b10100000110110, //'W' - 0b10110010000000, //'X' - 0b1010010000000, //'Y' - 0b10010000001001, //'Z' - 0b111001, //'[' - 0b100010000000, //'\' - 0b1111, //']' - - 0b1000, //'_' - 0b10000000, //'`' - 0b101011111, //'a' - 0b100001111000, //'b' - 0b101011000, //'c' - 0b10000100001110, //'d' - 0b1111001, //'e' - 0b1110001, //'f' - 0b110001111, //'g' - 0b101110100, //'h' - 0b1000000000000, //'i' - 0b1110, //'j' - 0b1111000000000, //'k' - 0b1001000000000, //'l' - 0b1000101010100, //'m' - 0b100001010000, //'n' - 0b101011100, //'o' - 0b10001110001, //'p' - 0b100101100011, //'q' - 0b1010000, //'r' - 0b110001101, //'s' - 0b1111000, //'t' - 0b11100, //'u' - 0b10000000010000, //'v' - 0b10100000010100, //'w' - 0b10110010000000, //'x' - 0b1100001110, //'y' - 0b10010000001001, //'z' - 0b10000011001001, //'{' - 0b1001000000000, //'|' - 0b110100001001, //'}' - - 0b11111111111111, //Unknown character - }; - + //moved alphanumeric_segs array outside of function uint16_t characterPosition = 65532; //space if (displayChar == ' ') characterPosition = 0; - //Symbols - else if (displayChar >= '#' && displayChar <= '>') - { - characterPosition = displayChar - '#' + 1; - } - //Upper case letters + symbols - else if (displayChar >= 'A' && displayChar <= ']') - { - characterPosition = displayChar - 'A' + 1 + 28; - } - //Symbols + lower case letters - else + //Printable Symbols + else if (displayChar >= '!' && displayChar <= '~') { - characterPosition = displayChar - '_' + 1 + 28 + 29; + characterPosition = displayChar - '!' + 1; } uint8_t dispNum = digitPosition / 4; @@ -667,6 +663,26 @@ void HT16K33::printChar(uint8_t displayChar, uint8_t digit) illuminateChar(alphanumeric_segs[characterPosition], digit); } +//Update the lookup table of segments for a particular character +bool HT16K33::defineChar(uint8_t displayChar, uint16_t segmentsToTurnOn) +{ + bool result = false; + + //Check to see if character is within range of displayable ASCII characters + if (displayChar >= '!' && displayChar <= '~') + { + //Get the index of character in map and update its 14-bit segment value + uint16_t characterPosition = displayChar - '!' + 1; + + //Mask the input segment value to 14 bits only + alphanumeric_segs[characterPosition] = (segmentsToTurnOn & 0x3FFF); + + //We're all good + result = true; + } + return result; +} + /* * Write a byte to the display. * Required for Print. diff --git a/src/SparkFun_Alphanumeric_Display.h b/src/SparkFun_Alphanumeric_Display.h index 117f6c6..58cd5ac 100644 --- a/src/SparkFun_Alphanumeric_Display.h +++ b/src/SparkFun_Alphanumeric_Display.h @@ -5,6 +5,8 @@ Priyanka Makin @ SparkFun Electronics Original Creation Date: July 25, 2019 https://github.com/sparkfun/SparkFun_Alphanumeric_Display_Arduino_Library +Updated April 30, 2020 by Gaston Williams to add defineChar function + Pickup a board here: https://sparkle.sparkfun.com/sparkle/storefront_products/16391 This file prototypes the HT16K33 class, implemented in SparkFun_Alphanumeric_Display.cpp. @@ -119,6 +121,9 @@ class HT16K33 : public Print void printChar(uint8_t displayChar, uint8_t digit); bool updateDisplay(); + //Define Character Segment Map + bool defineChar(uint8_t displayChar, uint16_t segmentsToTurnOn); + //Colon and decimal bool decimalOn(); bool decimalOff();