Using variables in a loop

I’m trying to use a loop to avoid duplicating allot of code over and over. Basically when a pin goes HIGH (or is held HIGH) I need to play a sound.

So far I’ve tried…

// loop from the lowest pin to the highest:
for (int thisPin = 0; thisPin < pinCount; thisPin++) {
if ((pinplay[thisPin] == 0) && (digitalRead(pin[thisPin]) == HIGH)) {
pinplay[thisPin] = 1;
if (digitalRead(pin[thisPin]) == LOW) {
pinplay[thisPin] = 0;

void doplay (int value) {;
//value of 1 would play 0001.mp3

…but [thisPin] doesn’t seem to actually input the number in all instances? I’m getting compile error: expected { before ) token

Any other way to accomplish this?

Try this instead:


You might also be interested in my DFPlayer library if your project has a speed requirement: library.