I have 2 arrays, one is the input pins and the other is the input variables:
int pins[] = {A0,A1,A2,A3,A4,A5};
int variables[] = {150,225,300,375,450,525,600,675,750,825,900};
This gives me 66 input options and I want to serial print something different for each option. How do I make these work like a matrix instead of having pages of 'if' statements?
How do I make these work like a matrix instead of having pages of 'if' statements?
A 2D array of char *s comes to mind. But, a switch statement with 66 cases would be easier on SRAM.
I think you you explain yourself very bad.
Tell me if what you mean to write was something like:
I have a matrix keyboard using my analog inputs. For each input I have several resistors and switches that leaves to me this values of analog values each time one key is pressed:
int variables[] = {150,225,300,375,450,525,600,675,750,825,900};BTW, my inputs are stored in a array like this:
int pins[] = {A0,A1,A2,A3,A4,A5};This gives me 66 input options and I want to serial print something different for each option. How do I make these work like a matrix instead of having pages of 'if' statements?
If the problem is this, my answer is: Use for loops. Something like:
for (int pin=0; pin<6; pin++) {
int adcKey = analogRead(pins[pin]);
for (int value=0; value<11; value++) {
if ( adcKey < variables[value] ) {
int key = constKey[pin][value];
}
}
}
You can improve this code, but the idea is this. NOTE that you must to create another matrix in this case a constKey[6][11], with the constant value of each key. After this you can have a switch/case to process the key. Instead of use the constKey you can use a matrix with the values to write to the serial port and adapt the code for that.