0

I am a Java guy trying to write some stuff in C++ for an Arduino project I have. What I've got is a matrix of LED lights which I am trying to draw letters on. I have setup a 2D array for each character, and now am trying to create a function that will draw the proper character on the LED board in a given position.

For example, I have defined,

boolean y[8][5]={
{1,0,0,0,1},
{0,1,0,1,0},
{0,1,0,1,0},
{0,0,1,0,0},
{0,0,1,0,0},
{0,0,1,0,0},
{0,0,1,0,0},
{0,0,1,0,0}};

Then ideally, I would like to have a function that takes a single character input and the x,y position of where the character should be placed in the light array.

However, I can't find a way to get the function to select the proper 2D array. I tried if statements, where

if(charIn=='y'){
charMap={
{1,0,0,0,1},
{0,1,0,1,0},
{0,1,0,1,0},
{0,0,1,0,0},
{0,0,1,0,0},
{0,0,1,0,0},
{0,0,1,0,0},
{0,0,1,0,0}};;
}

but then when I actually want to use charMap, it says it has not been created...even with a catchall else statement that guarantees its creation.

Any ideas for how I can get the function to recognize which 2D array it needs to use based upon an input character?

1 Answers1

-3

You could do this

bool letters[24][8][5];
//24 for 24 letters

and then to access every letters you would just need

int letter_index = (int)charIn - 97;
int charMap[8][5] = letters[letter_index];

for capital letters you would do this

int letter_index = (int)charIn - 65;
int charMap[8][5] = letters[letter_index];

ofc you would have to make sure if the input is in alphabet or this will get you out of bounds exception.

Lorence Hernandez
  • 1,189
  • 12
  • 23
  • 2
    Handy reading: [What is a magic number, and why is it bad?](https://stackoverflow.com/questions/47882/what-is-a-magic-number-and-why-is-it-bad) – user4581301 Jul 04 '18 at 01:36
  • 2
    `int charMap[8][5] = letters[letter_index];` is an error, arrays or pointers cannot be used as initializer for `int` – M.M Jul 04 '18 at 01:42
  • Lexicographical order of course! I was actually using the lex order for something else in the same project, but never thought about making a 3D array with first dimension being lexi id for this method. This is exactly the kind of thing I was looking for, thanks! – Mitchell H Jul 04 '18 at 01:44
  • You are getting downvoted, but I am not sure why. I currently have an LED display putting out the characters I need thanks to you... – Mitchell H Jul 04 '18 at 02:28
  • @MitchellH Read the comments and you will know why. –  Jul 04 '18 at 02:54