Using variables to easily change String or Int Array values?
hi there. i'm coding button box sim racing uses 12-way rotary switch determine of various button values , messages output.
so example, if i'm on position 1, might want messages output buttons different if on position 2 or 3 etc...
my thought use array string variables , int variables , use string variables change message stored in array, , int variables change keyboard value depending on switch positions.
the message updates seem not happening , i'm trying figure out why not working. been 15 years since did coding i'm rusty. looking help. thanks!
so example, if i'm on position 1, might want messages output buttons different if on position 2 or 3 etc...
my thought use array string variables , int variables , use string variables change message stored in array, , int variables change keyboard value depending on switch positions.
the message updates seem not happening , i'm trying figure out why not working. been 15 years since did coding i'm rusty. looking help. thanks!
code: [select]
void setup() {
//gameval , blkboxval store values of 12 way selectors
//initialize 12 way black box dial messages
string blkboxvalmsg1 = "";
string blkboxvalmsg2 = "";
string blkboxvalmsg3 = "";
string blkboxvalmsg4 = "";
//initialize array variables defined above 12 way black box dial
string blkboxvalmsg[] = { "", blkboxvalmsg1, blkboxvalmsg2, blkboxvalmsg3, blkboxvalmsg4 };
//initialize blackbox twelve way keys may or may not used output keyboard character game
int blkboxchar1 = 0;
int blkboxchar2 = 0;
int blkboxchar3 = 0;
int blkboxchar4 = 0;
//initialize array blackbox keys may change values
const int twelvewayblkboxkeys[] { 0, blkboxchar1, blkboxchar2, blkboxchar3, blkboxchar4 };
}
void loop()
{
//code left out: first check see if gameval or blkboxval have changed, if execute below code
if (gameval == 1) //change messages , set characters 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 , set characters 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 , press key
{
lcd.print(blkboxvalmsg[blkboxval]);
keyboard.press(twelvewayblkboxkeys[blkboxval]);
delay(150);
keyboard.release(twelvewayblkboxkeys[blkboxval]);
}
}
seems have duplicated local variables in setup - have global ones did not see either same name?
read variable scope
(its better post full sketch, more not issue looking in unsuspected part)
read variable scope
(its better post full sketch, more not issue looking in unsuspected part)
Arduino Forum > Using Arduino > Programming Questions > Using variables to easily change String or Int Array values?
arduino
Comments
Post a Comment