I'm pretty new to coding in Arduino, so bear with me here. I've been floating around the forum and searching every phrasing of my question I can come up with, but I can't find anything that directly answers what I'm looking for.
Basically, I have an LCD screen with 4 buttons, and the screen is going to display custom characters and do miscellaneous things based on button presses. But, what those custom characters are is defined by which "language" the user selects at the beginning of the code (there are 3 different 26-letter alphabets to choose from). So, those custom characters need to be global so that they can be referenced in all the following functions.
I have it set up so that the user presses a button to select the language which outputs a specific case variable which then indicates which set of custom characters needs to be made the "global alphabet". Basically, the user clicks a button, and depending on which button they click, one of the custom alphabets is selected. However, I'm stuck in that I'm seeing everyone saying that no code will run outside of functions in the global space. I don't have the hardware set-up currently to actually test the code (it's more complicated than just an LCD, and I'm waiting on parts to come in), but based on what I'm reading, it seems like having a SWITCH or IF statement outside of the main functions wouldn't work. So, how do declare my alphabet outside of my main functions to make it global while not being able to run a SWITCH/IF outside the functions?
I have a couple dozen functions that are called inside my main loop, so I don't think redefining all 26 characters inside each sub-function is a good idea. That's why I wanted them global. But if what's below won't work, I'm not sure what else to do.
Below is a watered-down version of what I have (watered-down because the code is long and frankly repetitive so I'm cutting it down to make it more palatable).
//sets up lanPinChanged as global variable for language check, sets to unused pin number
int lanPinChanged = 14;
void setup() {
//Choose Font Language
byte qma[8] = {B00010, B01010, B01010, B01010, B01010, B01010, B01010, B00010};
byte qaa[8] = {B10001, B10010, B11100, B00000, B00000, B11100, B10010, B10001};
byte qla[8] = {B00100, B01010, B10001, B10001, B11111, B10001, B10001, B10001};
lcd.createChar(0, qma);
lcd.createChar(1, qaa);
lcd.createChar(2, qla);
lcd.setCursor(1, 1); lcd.write(byte(0));
lcd.setCursor(5, 1); lcd.write(byte(1));
lcd.setCursor(9, 1); lcd.write(byte(2));
void loop(){
lanPinChanged = checkPush(0); //checks which pin is triggered (will loop until something is changed), lanPinChanged will become the associated pin number when a button is pressed
if (lanPinChanged != 14 && lanPinChanged != 7){
//7 is the unused 4th button, so pressing it shouldn't break the loop. Only 4-6 are used as buttons.
break;
}
}
}
switch (languageChoice) {
case 4: //Language1
byte mya[8] = {B00010, B01010, B01010, B01010, B01010, B01010, B01010, B00010};
...
byte myz[8] = {B01110, B00100, B00100, B00110, B00100, B01100, B01100, B00100};
break;
case 5: //Language2
byte mya[8] = {B00010, B01010, B01010, B01010, B01010, B01010, B01010, B00010};
...
byte myz[8] = {B01110, B00100, B00100, B00110, B00100, B01100, B01100, B00100};
break;
case 6: //Language3
byte mya[8] = {B00010, B01010, B01010, B01010, B01010, B01010, B01010, B00010};
...
byte myz[8] = {B01110, B00100, B00100, B00110, B00100, B01100, B01100, B00100};
break;
}
void loop(){
//the rest of the code which references the custom alphabet chosen
}