Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions examples/Example10_DefineChar/Example10_DefineChar.ino
Original file line number Diff line number Diff line change
@@ -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 <SparkFun_Alphanumeric_Display.h>
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");
}
3 changes: 2 additions & 1 deletion examples/Example7_unkownChar/Example7_unkownChar.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down
246 changes: 131 additions & 115 deletions src/SparkFun_Alphanumeric_Display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,17 @@ 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
from printing to one or more Alphanumeric Displays, changing the display settings, and writing/
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:
Expand Down Expand Up @@ -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++)
Expand Down Expand Up @@ -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;
Expand All @@ -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.
Expand Down
5 changes: 5 additions & 0 deletions src/SparkFun_Alphanumeric_Display.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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();
Expand Down