if statement to test if a number has changed X value (input)

hello,
is It possible to take an input value that sitting at X value and use something like a IF statement to look for Y change?

IF X or 100 changes + or - 1 (Y) // (99 or 101) then run {}
or
IF X or 100 changes + or - 5 (Y) //(95 or 105) then run {}

keep in mind the input will change so the 100 or X value will be trigger IF change is by 1 or 5 or whatever I set it Y too

so if I turn a POT it will only run IF the change is by Y much

thanks

if (value >95 && value <105){
// action
}

or
if (value >=95 && value <+105){
// action
}

Yes.

For details, look up the function abs(...) and/or look up the logical operators.

CrossRoads probably meant for the <+105 to be <=105 .

sorry, you misunderstood ill try explain better

I don't what to present the range.

I want to say if the X value which is an analogue input. changes by Y amount, be it 1, 5, 10 then run if or other command.

if set to 5 then when input X = 100 and it changes to 101 nothing or 102 nothing. until it sees 105

BUT as I said X changes as input so I only want a trigger when its more then Y amount

thanks

CrossRoads:

if (value >95 && value <105){

// action
}

or
if (value >=95 && value <+105){
// action
}

thanks , this is something of what I was thinking...
it works...BUT if the input changes to quick it will skip the IF

//works only when pot changes
if (val - valnew ==2)
{ lcd.print(" "); valnew = val; myservo.write(valnew);}
delay(10);

it needs to go both ways and if the value changes the other way I get a NEGATIVE and it wont work.

Delta_G:
So you need to keep track of the old value and save it when you read a new value. Simple subtraction tells the difference between the two.

if(oldValue - newValue >= 5)

Or wrap that whole expression in abs() if you want plus or minus.

Delta_G:
So you need to keep track of the old value and save it when you read a new value. Simple subtraction tells the difference between the two.

if(oldValue - newValue >= 5)

Or wrap that whole expression in abs() if you want plus or minus.

Being able to read has its advantages.

if(abs(oldValue - newValue) >= 5)

BUT if the input changes to quick it will skip the IF

No.