elvum:
The plan was:
1st: read the analog value
2nd: store the analog value in the variable "prevState"
(the delay was set here to make shure i don't get the same result from the sensor twice... )
3rd: read the analog value again and compare it with the "prevSate"
Instead of reading it twice, just read it once, and at the end of the loop, store the result into a static or global variable; you don't even need the delay because of some calculus principle that I can't remember about having to hit a value if you have a continuous function that crosses that value.