Hi, I am trying to come up with a simple program where I can have several data arrays which will be displayed as I turn a dial. ie. encoder position one would display the 4 parameters of AC42 on a small oled. I am at the end of my rope trying to figure why this won't work! Many thanks to anyone who can help me solve this!
int mp9Data1 = 130;
int mp9Data2 = 80;
int mp9Data3 = 130;
int mp9Data4 = 138;
int MP9[] = {mp9Data1,mp9Data2,mp9Data3,mp9Data4};
int ac42Data1 = 130;
int ac42Data2 = 80;
int ac42Data3 = 130;
int ac42Data4 = 135;
int AC42[] = {ac42Data1,ac42Data2,ac42Data3,ac42Data4};
String weaponList [] = {MP9,AC42};
String selectedWeapon;
int encoderPosition = 1; //I will link a rotary encoder to this
void setup() {
Serial.begin(9600);
Serial.println("array test");
}
void loop() {
selectedWeapon = weaponList[encoderPosition];
Serial.println(selectedWeapon[0]);
Serial.println(selectedWeapon[1]);
Serial.println(selectedWeapon[2]);
Serial.println(selectedWeapon[3]);
delay (1000);
}
I declared the encoder poison. Yes, I can not change it on the fly, but this is to create a sketch to help me understand arrays. I understand many other aspects of arduino programming, but I have never used arrays. No need to rant at me, I already know I don't understand arrays. I thought this was a forum to help others, no?
So would you like me to move your code to the appropriate section? This section you posted in is for help for you to learn, not a code writing service.
this is not a real project. I can't begin to understand the correct way to write this code playing games. I learn by seeing the whole picture, after that, I will be able to continue with my actual project.
yes, I got that part. But how would I control the selected array to output the data via the selection using an int from the encoder? Thats the part Im having trouble with.
So you knew that part already, so no thanks for pointing me in the right direction? If you knew it already then why was your code a million miles away?
This is a beginning of a rant, so I solved one problem and now you want another solved?
See what I did about the names? Do it with the numbers.
I think you may have made a point about the other problem, too - which makes the encoder part easy and Im working on it. you said "there is no need to use strings" which I couldn't see how because in the same breath you also said my code doesn't have an encoder so "what you posted will never work" lol.
ok it works! it was going "round the houses" way to figure it out but it works!
int mp9Data1 = 999;
int mp9Data2 = 888;
int mp9Data3 = 777;
int mp9Data4 = 666;
int mp9Data5 = 555;
int MP9[] = {mp9Data1,mp9Data2,mp9Data3,mp9Data4,mp9Data5};
int ac42_Data1 = 111;
int ac42Data2 = 222;
int ac42Data3 = 333;
int ac42Data4 = 444;
int ac42Data5 = 555;
int AC42[] ={ac42_Data1,ac42Data2,ac42Data3,ac42Data4,ac42Data5};
int k30Data1 = 101;
int k30Data2 = 202;
int k30Data3 = 303;
int k30Data4 = 404;
int k30Data5 = 505;
int K30[] ={k30Data1,k30Data2,k30Data3,k30Data4,k30Data5};
int g57Data1 = 601;
int g57Data2 = 602;
int g57Data3 = 603;
int g57Data4 = 604;
int g57Data5 = 605;
int G57[] ={g57Data1,g57Data2,g57Data3,g57Data4,g57Data5};
#define numberOfSettings 5 // must be == to number of gun settings. all guns must have the same numnber of settings.
int *weaponList []={MP9,AC42,K30,G57};
int selectedWeapon[numberOfSettings];
int encoderPosition = 3;
void setup() {
Serial.begin(9600);
Serial.println("array test");
}
void loop() {
selectweapon(encoderPosition);
Serial.println();
Serial.println(selectedWeapon[0]);
Serial.println(selectedWeapon[1]);
Serial.println(selectedWeapon[2]);
Serial.println(selectedWeapon[3]);
Serial.println(selectedWeapon[4]);
delay (1000);
}
void selectweapon(int x) {
for(int i = 0; i<numberOfSettings; i++) {
selectedWeapon[i] = weaponList[x][i];
}
}