Hi there. I'm currently coding a button box for Sim Racing which uses a 12-way rotary switch to determine some of the various button values and messages that are output.
So for example, if I'm on position 1, I might want the messages output by certain buttons to be different than if I was on position 2 or 3 etc...
My thought was to use an array with string variables and another with int variables and use those string variables to change the message stored in the array, and the int variables to change the keyboard value depending on switch positions.
The message updates seem to not be happening and I'm trying to figure out why its not working. Been about 15 years since I did any coding so I'm definitely rusty. Looking for help. Thanks!
void setup() {
//gameVal and blkBoxVal store the values of the 12 way selectors
//Initialize the 12 way black box dial messages
String blkBoxValMsg1 = "";
String blkBoxValMsg2 = "";
String blkBoxValMsg3 = "";
String blkBoxValMsg4 = "";
//Initialize the array with the variables defined above for the 12 way black box dial
String blkBoxValMsg[] = { "", blkBoxValMsg1, blkBoxValMsg2, blkBoxValMsg3, blkBoxValMsg4 };
//Initialize the BlackBox Twelve Way Keys which may or may not be used to output a keyboard character to the game
int blkBoxChar1 = 0;
int blkBoxChar2 = 0;
int blkBoxChar3 = 0;
int blkBoxChar4 = 0;
//Initialize the array with the blackbox keys which may change their values
const int twelveWayBlkBoxKeys[] { 0, blkBoxChar1, blkBoxChar2, blkBoxChar3, blkBoxChar4 };
}
void loop()
{
//CODE LEFT OUT: FIRST CHECK TO SEE IF THE gameVal or blkBoxVal have changed, if so then execute below code
if (gameVal == 1) //change messages and set characters to nothing
{
blkBoxValMsg1 = "ADJ BRAKE BIAS"; blkBoxValMsg2 = "FRONT SWAY BAR";
blkBoxValMsg3 = " REAR SWAY BAR"; blkBoxValMsg4 = " ADJ SEAT POS ";
blkBoxChar1 = 0; blkBoxChar2 = 0; blkBoxChar3 = 0; blkBoxChar4 = 0;
}
else if (gameVal == 2) //change messages and set characters to F1-F4
{
blkBoxValMsg1 = " LAP TIMING "; blkBoxValMsg2 = " STANDINGS ";
blkBoxValMsg3 = "RELATIVE TIMING"; blkBoxValMsg4 = " FUEL SETTINGS ";
blkBoxChar1 = 0xC2; blkBoxChar2 = 0xC3; blkBoxChar3 = 0xC4; blkBoxChar4 = 0xC5;
}
if (gameVal == 1 && blkBoxVal == 1)
{
lcd.print(blkBoxValMsg[blkBoxVal]);
}
else if (gameVal == 2 && blkBoxVal == 1) //different game, output different message and press a key
{
lcd.print(blkBoxValMsg[blkBoxVal]);
Keyboard.press(twelveWayBlkBoxKeys[blkBoxVal]);
delay(150);
Keyboard.release(twelveWayBlkBoxKeys[blkBoxVal]);
}
}