Reading digital input from multiple piezos

Here is the code and wiring for connecting multiple piezos to digital pins:

const int numSensors = 2;
const int buttonPin[numSensors] = {2,3};

int sensorReading[numSensors] = {0, 0};
boolean buttonState;

void setup() {
 
 for (int i = 0; i < numSensors; i++)
 {
     pinMode(buttonPin, INPUT);  
 }
 
 Serial.begin(9600);
}

void loop(){
 
  for (int i = 0; i < numSensors; i++)
 {
    buttonState = digitalRead(buttonPin);

    if (buttonState == HIGH) { 
      
      Serial.println(buttonPin);

     } 
 }
}

Here is the code and wiring for connecting multiple piezos to digital pins:

Just think how much nicer it would have been if you had used more appropriate data types, formatted the code better and used code tags when posting it.

Do you have a question relating to the code ?

Please post your so we can check it.
—- thanks for the tags,

I’m guessing this compiles without errors...?
—- well ok, not really

I'm guessing this compiles without errors...?

You guessed wrongly

Why would you name the pin connecting the piezo "buttonPin". Is there a button there you haven't told us about?

I suppose there is a reason buttonPin[] is declared as an array, yetis referenced as a single variable?

I suspect that the code got mangled when it was initially posted without code tags and the usual problems with [­i] array subscripts occurred and they have not been added back.

It's a bit better in the other places where the same thing is posted.
https://forum.arduino.cc/index.php?topic=531800.0
https://forum.arduino.cc/index.php?topic=531791

This one must have been an early attempt.

Steve

@elefley, please stop cross-posting.

slipstick:
It's a bit better in the other places where the same thing is posted.

Seriously? Ugh. Be back in a bit... Yup. Threads merged. The second one is probably the "better" one.

So, after wasting a few minutes of my life cleaning up the mess, I will revise my post above...

@elefley, do not cross-post ever again.