ok, photo resistors can return a great range of values...in an if statement, is there a way to make it so the value has a range....a certain threshold? like, if(x=y){//do code here} but, for x to = y, x has to only be within 50 of y? for example, y = 100. x = 0. x is not = to y...but now x is changed to say, 79, it is withing 50 of y so x = y. and that same for the other way, like x = 200 and y = 100. x is not = to y. x is changed to 120, it is within the threshold of 50 from y, so x = y. is there any way to do this? any statement to do this in? i need help REALLY BAD!
try
if (x > (y-50)) {
//do something
}
^ that's only if you want a bottom threshold
if you want x to be at least 50 close to y from both sides, then use
if (x > (y-50) && x < (y+50)){
//do something
}
Another possibility is to divide the returned value by some number to get a smaller set of returned values. E. g. let's say the range was from 0-127. If we divide the returned value by 16, then the result would be a number in the range of 0-7. It's easy to set up a switch statement to handle that:
switch (x/16) {
case 0:
// do whatever at zero (or 0-15 values of x)
break;
case 1:
// do whatever at zero (or 16-31 values of x)
break;
case 2:
// do whatever at zero (or 32-47 values of x)
break;
...
}
Jim.