How to count array elements

YES! That's all I need. I want to read a bunch of individual button inputs as numbers.

int readArray[] = {0,0,0};

int readFunct()
{

for (int i = 0; i<3; i++)
{
if (readArray[i] = 1)
{
return 1;
}
}
return 0;
}

void setup()
{
  pinMode(10, INPUT_PULLUP);
  pinMode(11, INPUT_PULLUP);
  pinMode(12, INPUT_PULLUP);
  
  Serial.begin(9600);
}

void loop()
{
  Serial.println(" ");
  readArray[0] = digitalRead(10);
  readArray[1] = digitalRead(11);
  readArray[2] = digitalRead(12);
  
  Serial.println(readFunct());
  delay(1000);
}

It's not sinking in, is it?

The only change I can see is a modification of the return value and a change in the way that readArray is defined. Is that it?

Then why does @cotestatnt's code work?

int readFunct(){
  for (int i = 0; i < 3; i++){
    if (readArray[i] == 1){      
      return i + 1;      
    }
  }
  return 0;
}

If this is about the = vs ==, I just tried that in my own code and it still prints 1s.

Your main error as my opinion, is in the loop().
You don't assign values to the elements in the array.

I think I see the problem(s).

Apart from the assignments to the elements of the array?

Just use a button library. Here's one using a button library I wrote for myself but any will do:

I have the suspect he thougth this

will link the variables involved togheter

1 Like

That’s exactly what I thought.

What is IT?

The output of the code.

So, i will offer the next level for you gratis :rofl:

But you have to study about pointers

I am terribly sorry. I cannot see the code on your computer.

Post #82.

Your code combined with my code prints 1s.

LOL. This is a styling way to learn. Or not.

a7

Please. Please. Please. Please. Please. Please. Please. Please. Please. Please. Please. Please. Please. Please. Please. Please.

Post the entire code you are using to get the not working thingy.

Post #82.

The equals sign has been fixed. I’m on my phone now so I can’t get to the updates code, but it’s only 1 character.

please post the code you are currently using, the entire code.