...then how do I figure out where the 1 is as an int value? Like how do I convert that into just saying 3, as in the third element is the 1. If the fifth element was the one, the value would be 5.
Obviously a for() loop function is used, but I was unable to get the following code with 3 values read from buttons working:
int read1;
int read2;
int read3;
int read;
int val;
int readArray[3] = {read1, read2, read3};
int readFunct(){
for (int i; i >= 2; i++){
if (readArray[i] = 1){
read = i;
return read;
break;
}
}
}
void setup()
{
pinMode(10, INPUT_PULLUP);
pinMode(11, INPUT_PULLUP);
pinMode(12, INPUT_PULLUP);
Serial.begin(9600);
}
void loop()
{
read1 = digitalRead(10);
read2 = digitalRead(11);
read3 = digitalRead(12);
readFunct();
Serial.println(read);
}
EDIT - If you're wondering what it does, it just reads 0s.
As the value "i" counts up, the loop checks each value in the array for a 1. If there's a 1, the loop sets the value "read" to the amount of counts taken, returns the value, and then breaks off.