Maybe something like this?
/********************************************************************************
This data structure represents one frame.
********************************************************************************/
struct frame_t
{
char symbol;
byte content[6];
};
/********************************************************************************
This is the array storing all the possible frames. The symbol field in
the frame_t data structure is used to map the frame to the symbol it
represents.
Example: A is represented by {0x7E, 0x88, 0x88, 0x88, 0x7E, 0x00}
<frame_t>.symbol = 'A';
<frame_t>.content = {0x7E, 0x88, 0x88, 0x88, 0x7E, 0x00};
*******************************************************************************/
frame_t frameMap[] = {
{'A', {B01111110,B10001000,B10001000,B10001000,B01111110,B00000000}},
{'r', {B00010000,B00100000,B00100000,B00010000,B00111110,B00000000}},
// define more characters or frames
};
/********************************************************************************
This functions retrieves a frame from the map. It uses the symbol field
in the frame_t structure to find the correct frame in the map. It returns
either a pointer to the frame or a nullptr, if no frame could be found in
the map.
********************************************************************************/
frame_t* getFrameFromMap(char value)
{
uint8_t mapSize = sizeof(frameMap) / sizeof(frame_t);
for(uint8_t i = 0; i < mapSize; i++)
{
if(frameMap[i].symbol == value)
{
// found the mapping
return &frameMap[i];
}
}
// no frame found
return nullptr;
}
/********************************************************************************
Call this function when you want to display a text. It will iterate over
the text and display each character. For this, it gets the frame
representing the character using the getFrameFromMap function.
The scrollSpeed controls how long the character is shown.
********************************************************************************/
void showText(const char* text, float scrollSpeed)
{
while(*text != '\0')
{
frame_t* frame = getFrameFromMap(*text++);
if(frame == nullptr)
{
// do error handling, character was not in the map
}
else
{
displayFrame(frame);
}
delay(200 * scrollSpeed);
}
}
I haven't had the chance to test or compile it, but you can use it to implement your version.
Basically you'll have an array of frames. Each frame, is mapped to a corresponding symbol or character in the frameMap array. The function showText uses the helper function getFrameFromMap(char) to get a frame from the frameMap, that represents the character that should be shown on the display.
The rest of the could should be pretty self-explanatory, be aware of the delay in the showText function though. To compile this you will need to have a function
void displayFrame(frame_t* frame)
{
// send the frame to the display as you've already implemented
// you can access the data through frame->content.
}