Not sure if this is the right way to put my code on here, but here is the CharliePlexing code I'm using. If there are things I can do to simplify, PLEASE let me know... I want to spend some time getting rid of the string array stuff and going to straight string since i'm now always using a single string character, but everytime I try it doesn't get happy because of how it passes the pointers.
// where does our characterMap start in the ASCII code
#define MAP_START 32
#define DISPLAY_WIDTH 4
#define DISPLAY_HEIGHT 5
#define DISPLAY_STRING "6"
// maps characters to their 4x5 grid
//CharacterMap is a long value that can be up to 60 characters long
unsigned long characterMap[59];
char myString[] = DISPLAY_STRING;
// set up the character from the render map
void Chr(char theChar, unsigned long value)
{
//Converts Character 2 to its long value
characterMap[theChar - MAP_START] = value;
}
//Converts Character 2 to the myString array
void renderString(char *theString)
{
renderCharacter(theString[0]);
}
// render a character on the given offset
void renderCharacter(char theChar)
{
unsigned long graphic = characterMap[theChar - MAP_START];
for (byte y = 0; y < DISPLAY_HEIGHT; y++)
{
for (byte x = 0; x < DISPLAY_WIDTH; x++)
{
if (graphic & 1)
{
lightPixel(3 - x, y);
}
graphic = graphic >> 1;
}
}
}
// light a pixel at the given coordinates
void lightPixel(byte x, byte y)
{
//if x is less than or equal to 0 and x is greater than 4
if (x >= 0 && x < DISPLAY_WIDTH)
//if y is less than x then make x equal x + 1
{
if (y <= x)
{
x++;
}
LEDon(y, x);
}
}
// turn on the pins to light a LED
void LEDon(byte vin, byte gnd)
{
pinMode(0, INPUT);
pinMode(1, INPUT);
pinMode(2, INPUT);
pinMode(3, INPUT);
pinMode(4, INPUT);
pinMode(vin, OUTPUT);
pinMode(gnd, OUTPUT);
digitalWrite(vin, HIGH);
digitalWrite(gnd, LOW);
}
// runs at start
void setup()
{
// set up render map
// Rows: 1---2---3---4---5---
Chr('D', 0b11101001100110011110);
Chr('N', 0b10011101101110011001);
Chr('O', 0b01101001100110010110);
Chr('P', 0b11101001111010001000);
Chr('R', 0b11101001111010101001);
Chr('X', 0b10011001011010011001);
Chr(' ', 0b00000000000000000000);
Chr('!', 0b01000100010000000100);
Chr('1', 0b01100110011001100110);
Chr('2', 0b11110001111110001111);
Chr('3', 0b11110001111100011111);
Chr('4', 0b10011001111100010001);
Chr('5', 0b11111000111100011111);
Chr('6', 0b10001000111110011111);
}
// loops continuously
void loop()
{
renderString(myString);
}