I am experimenting with user defined characters on an LCD and have the basics working OK. The characters are defined in byte arrays and created using createChar with the usual parameters of character number to be created and the name of the array to be used.
I am creating characters on the fly inside a for loop. This works and I can put up with the fact that redefining a character causes instances of it previously displayed on the LCD to be changed. Currently the name of the array to be used in the character definition is selected using switch case based on the value of the for loop variable but this is very clumsy. What I would like to do is to use the values of 2 nested for loop variables as the second parameter but I don't know if this is possible and, if it is, the syntax to be used.
An extra complication seems to be that the names of the arrays cannot be numeric but must must start with an alphabetic character so this will need to be concatenated to the front of the combined loop variable names.
Did I mention that I am new to C
Below is an example of the sort of thing that I would like to do. Is it possible, and if so, how ?
Bob
/*
Illustration of how I would like to define LCD
characters on the fly using loop variables as the array name
*/
#include <LiquidCrystal.h>
byte p00[8] = {
B10000,
B00000,
B00000,
B00000,
B00000,
B00000,
B00000,
B00000,
};
byte p01[8] = {
B01000,
B00000,
B00000,
B00000,
B00000,
B00000,
B00000,
B00000,
};
byte p02[8] = {
B00100,
B00000,
B00000,
B00000,
B00000,
B00000,
B00000,
B00000,
};
byte p12[8] = {
B00000,
B00100,
B00000,
B00000,
B00000,
B00000,
B00000,
B00000,
};
byte p22[8] = {
B00000,
B00000,
B00100,
B00000,
B00000,
B00000,
B00000,
B00000,
};
byte p21[8] = {
B00000,
B00000,
B01000,
B00000,
B00000,
B00000,
B00000,
B00000,
};
byte p20[8] = {
B00000,
B00000,
B10000,
B00000,
B00000,
B00000,
B00000,
B00000,
};
byte p10[8] = {
B00000,
B10000,
B00000,
B00000,
B00000,
B00000,
B00000,
B00000,
};
void setup()
{
}
void loop()
{
for (int row=0; row<3;row++)
{
for (int col=0;col<3; col++)
{
//create the name of the array to be used in the definition
//I know that the the syntax is wrong and it may not be possible to do this anyway.
arrayName='p'+row+col;
lcd.createChar(1,arrayName);
lcd.setCursor(0,0);
lcd.write(1);
}
}
}