and remember the state
static const int somePin=9; // your input pin
int lastState; // define outside to keep its value
void setup()
{
lastState = digitalRead(somePin);
}
void loop()
{
int currState = digitalRead(somePin);
// compare currState with lastState here
// ...
lastState = currState; // remember for next loop round
}