Read multiply inputs state change?

I have about 10 digital inputs connected to arduino uno. Seweral with IO expander (PCF8574). They are like 2 positions buttons, take HIGH or LOW value and stay in it state.. I want to play a tone with speaker if any of those input change it state. I know how to do it with single input, but with 10 inputs code will become messy. Searching simple metod or smart library to check if state of any button was changed.

with 10 inputs code will become messy

Put the pin data (pin number and previous state) in an array of structs and iterate through it with a for loop

Write all the individual bits to a single int variable.
XOR this value with a variable containing the previous values read.
Any bits in the result which have the value 1 have changed since the last read.

Any example how to or what to type in google search? I'm not pro just more than beginer.

int result = currentReadings ^ previousReadings;
if (result) {
  Serial.println(F( "At least one input has changed"));
}
previousResults = currentReadings;

TheMemberFormerlyKnownAsAWOL:
Write all the individual bits to a single int variable.

Check out the bits and bytes section of the Arduino reference page.

bartek87:
I have about 10 digital inputs connected to arduino uno. Seweral with IO expander (PCF8574). They are like 2 positions buttons, take HIGH or LOW value and stay in it state.. I want to play a tone with speaker if any of those input change it state. I know how to do it with single input, but with 10 inputs code will become messy. Searching simple metod or smart library to check if state of any button was changed.

have 2 variables (16 bits each), type unsigned int
variable 1 points to the 10 physical digital inputs
variable 2 is a image of variable 1
variable1 = read digital inputs
if (variable1 != variable2) {
play sound;
}
variable2 = variable1

Check out StateChangeDetection example sketch that ships with the IDE.

Try this

struct inputData
{
  const byte pinNumber;
  byte previousState;
};

inputData inputs[] =
{
  {A3, HIGH},
  {A2, HIGH},
  {A1, HIGH},
  {A0, HIGH}
};
const byte NUMBER_OF_INPUTS = sizeof(inputs) / sizeof(inputs[0]);

void setup()
{
  Serial.begin(115200);
  while (!Serial);
  for (int pin = 0; pin < NUMBER_OF_INPUTS; pin++)
  {
    pinMode(inputs[pin].pinNumber, INPUT_PULLUP);
  }
}

void loop()
{
  boolean inputChanged = false;
  for (int pin = 0; pin < NUMBER_OF_INPUTS; pin++)
  {
    byte currentState = digitalRead(inputs[pin].pinNumber);
    if (currentState != inputs[pin].previousState)
    {
      inputChanged = true;
    }
    inputs[pin].previousState = currentState;
  }
  if (inputChanged == true)
  {
    Serial.println("an input changed state");
  }
}

TheMemberFormerlyKnownAsAWOL:

int result = currentReadings ^ previousReadings;

if (result) {
  Serial.println(F( "At least one input has changed"));
}
previousResults = currentReadings;

Wow, thx a lot, it help me much.
I have this and it's working and most important I learned something new about bit operations :wink:
in setup

  int previousReadings = 0b11111;     //initial state
  int currentReadings;

in loop, data[0]...[4] it's equal to digitalRead(pin_number)

  bitWrite(currentReadings, 0, data[0]);
  bitWrite(currentReadings, 1, data[1]);
  bitWrite(currentReadings, 2, data[2]);
  bitWrite(currentReadings, 3, data[3]);
  bitWrite(currentReadings, 4, data[4]);

  int result = currentReadings ^ previousReadings;
  if (result) {
  
  //code to do onece per state change
  previousReadings = currentReadings;
  }