Only If value has changed then...

I'm trying to write an If statement that basically checks if the value (input of an Arduino Nano) has changes since the last loop-through.

I can't find any direct statement, but I assume I have to use 2 variable and have it write the new value upon match and turn on a LED or other action.

Any suggestions?

Look at the state change example that comes with the IDE. You're on the right track. That will show you how to put it together.

I got something working:

// Get Switch State 1 and send HTTP request to HC2
SwitchState_1 = digitalRead(Input1);
if (SwitchState_1 != lastSwitchState_1) {
if (SwitchState_1 == HIGH) {
Input1_OPEN(client); // sents an http request to my home automation telling sensor = open
}
else {
Input1_CLOSED(client); // sents an http request to my home automation telling sensor = closed
}
}
lastSwitchState_1 = SwitchState_1;

In another arduino uno (just for a test) it works wereby the LED goes on/off. When i add this to the sketch for the arduino nano in a http request server (webserver) without webpage. connection is closed. so it waits until i got a incoming http request to switch one of the 4 relays, which are connected to the arduino nano too (4 inputs and 4 outputs) at that time it sent the input change to the home automation.

But that's not my purpose. my input needs to sent a http request any time it changes status, high or low. and should not wait till I got an incoming http request to switch one of the relays.

Any suggestions?

i got it working allready, thanks for the input