Detect weather a value is increasing or decreasing

That is exactly what you have to do. OldVal = NewVal; NewVal = InputVal;