Skip to content

Adding some "user contributions" to Examples and documentation #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Add files via upload
Add three new Examples that others may find useful.
  • Loading branch information
ClarkInAz authored Mar 18, 2021
commit 1c1acc259249c1b831d00ec7d3a38eeef927336b
70 changes: 70 additions & 0 deletions examples/Example11_SegmentNames.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@

/*******************************************************************************************
* This is based on the SparkFun Example 2 for the Spark-X
* alphanumeric display.
* This version cycles through the names, displaying a name
* and illuminating the corresponding segment on the next
* digit. Since the displays have 4 digits, we can show two
* at a time.
* Hardware Connections:
*
* Attach Red Board to computer using micro-B USB cable.
* Attach Qwiic Alphanumeric board to Red Board using Qwiic cable.
*
* I wrote this for my own use, but have decided to release
* it as "user contributed" to the general community.
*
* Written by Clark Jones, and released as "beerware", as-is,
* with abolutely no guarantees.
*****************************************************************************************/
#include <Wire.h>

#include <SparkFun_Alphanumeric_Display.h> //Click here to get the library: http://librarymanager/All#Alphanumeric_Display by SparkFun
HT16K33 display;

uint8_t currChar;
unsigned long nextDisplay;

void setup()
{
Serial.begin(115200);
Serial.println("Qwiic Alphanumeric examples");
Wire.begin(); //Join I2C bus

//check if display will acknowledge
if (display.begin() == false)
{
Serial.println("Device did not acknowledge! Freezing.");
while(1);
}
Serial.println("Display acknowledged.");

currChar = 'A';
nextDisplay = 0;
}

void loop()
{
unsigned long nowTime;
nowTime = millis();
// Rather than using the millis() value, delay(2000) could have
// been used, but if other things were going on, this allows
// for them to happen, thus being better "style".
if ( nowTime >= nextDisplay ) {
nextDisplay = nowTime + 2000;
display.clear();
display.printChar(currChar, 0);
display.illuminateSegment(currChar, 1);
Serial.print("Displaying segment ");
Serial.print(currChar);
currChar++;
display.printChar(currChar, 2);
display.illuminateSegment(currChar,3);
Serial.print(" and segment ");
Serial.println(currChar);
currChar++;
display.updateDisplay();
if ( currChar > 'N' )
currChar = 'A'; // Cycle around
}; // nowTime >= nextDisplay
}
83 changes: 83 additions & 0 deletions examples/Example12_ShowChars.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/****************************************************************
* This sketch will run through the poossible values that the
* Spark-X Alphanumeric Displays (SparkFun SPX-16391, SPX-16425,
* SPX-16426, and SPX-16427) can display, so that the user can
* easily see an example of each letter.
*
* The first two digits will be the hexadecimal ASCII value, and
* the fourth digit will actually display the character.
*
* Furthermore, a message is sent to the serial monitor stating
* what character is being displayed.
*
* I wrote this for my own use, but have decided to release
* it as "user contributed" to the general community.
*
* Written by Clark Jones, and released as "beerware", as-is,
* with abolutely no guarantees.
*/

#include <Wire.h>
#include <SparkFun_Alphanumeric_Display.h>

HT16K33 display;

unsigned long nextDisplayTime;

uint8_t showingChar;

void setup() {
Serial.begin(115200);
Serial.println("Qwiic Alphanumeric examples");
Wire.begin(); //Join I2C bus

//check if display will acknowledge
if (display.begin() == false)
{
Serial.println("Device did not acknowledge! Freezing.");
while(1);
}
Serial.println("Display acknowledged.");

nextDisplayTime = 0;
showingChar = '!';
}

void loop() {
unsigned long nowTime;
nowTime = millis();
if ( nowTime >= nextDisplayTime ) {
nextDisplayTime = nowTime + 2000;
display.clear();
char hexUpper, hexLower;
byte temp;
temp = showingChar >> 4; // faster than dividing by 16
if ( temp <= 9 ) {
hexUpper = '0' + temp;
} else {
hexUpper = 'A' + temp - 10;
};
temp = showingChar & 0x0F;
if ( temp <= 9 ) {
hexLower = '0' + temp;
} else {
hexLower = 'A' + temp - 10;
};
display.printChar( hexUpper, 0 );
display.printChar( hexLower, 1 );
display.printChar( (char)showingChar, 3 );
display.updateDisplay();
Serial.print( "Showing character '" );
Serial.print( (char)showingChar );
Serial.print( "' (0x" );
Serial.print( hexUpper );
Serial.print( hexLower );
Serial.println( ")" );
showingChar++;
if ( showingChar > '~' ) {
showingChar = '!';
}

}; // nowTime >= nextDisplayTime

}
103 changes: 103 additions & 0 deletions examples/Example13_QuickTest.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/***************************************************************
* This is intended as a "quick functionality test" of the
* Spark-X Alphanumeric Displays (SparkFun SPX-16391, SPX-16425,
* SPX-16426, and SPX-16427).
*
* The sketch will illuminate one segment on each digit, with
* each digit showing a different segment, cycling through all
* 14 segments twice, then illuminating the colon and then the
* decimal, before pausing briefly with a blank display then
* repeating the process.
*
* By the way, the reason for having the four digits "out of
* step", so to speak, is that it proves that each is being
* independantly addressed.
*
* Note that as it stands, it is intended to test only one
* display unit at a time, with the default address on the
* unit. However, it can easily be expanded to relax these
* restrictions, and can also be modified for use as a
* "power-on self test" at the beginning of a more complex
* sketch.
*
* I wrote this for my own use, but have decided to release
* it as "user contributed" to the general community.
*
* Written by Clark Jones, and released as "beerware", as-is,
* with absolutely no guarantees.
*/

#include <Wire.h>
#include <SparkFun_Alphanumeric_Display.h>

HT16K33 display;

uint8_t segSequence[14]{
// This is necessary because of the order that the segments
// are assigned letters -- it's easier for a human to view
// them and verify that all are working if they appear to
// "rotate".
'A', // top
'B', // upper right
'C', // lower right
'D', // bottom
'E', // lower left
'F', // upper left
'J', // upper middle vertical
'K', // upper right diagonal
'I', // middle right horizontal
'L', // lower right diagonal
'M', // lower middle vertical
'N', // lower left diagonal
'G', // middle left horizontal
'H' // upper left diagonal
};

int currStep;
unsigned long nextDisplayTime;

void setup() {
Serial.begin(115200);
Serial.println("Qwiic Alphanumeric examples");
Wire.begin(); //Join I2C bus

//check if display will acknowledge
if (display.begin() == false)
{
Serial.println("Device did not acknowledge! Freezing.");
while(1);
}
Serial.println("Display acknowledged.");

currStep = 0;
nextDisplayTime = 0;
}; // setup()

void loop() {
unsigned long nowTime;
nowTime = millis();
if ( nowTime >= nextDisplayTime ) {
nextDisplayTime = nowTime + 250;
display.clear();
if ( currStep < 28 ) {
// Display segments
// Notice that these will "wrap around" on segSequence
display.illuminateSegment( segSequence[ currStep % 14 ], 0);
display.illuminateSegment( segSequence[ ( currStep + 1 ) % 14 ], 1 );
display.illuminateSegment( segSequence[ ( currStep + 2 ) % 14 ], 2 );
display.illuminateSegment( segSequence[ ( currStep + 3 ) % 14 ], 3 );
} else if ( currStep == 28 ) {
display.colonOn();
} else if ( currStep == 29 ) {
display.decimalOn();
} else {
// Two things to notice: this generates a brief blank time
// and by setting currStep to -1 it will then get
// incremented to 0
currStep = -1;
};
display.updateDisplay();
currStep++;
}; // nowTime >= nextDisplayTime

}; // loop()