Try this
const int BELOW_THRES = 0;
const int ABOVE_THRES = 1;
int prevState = BELOW_THRES;
int thres = 500;
void setup() {
Serial.begin(9600);
}
void loop() {
int currValue = analogRead(A0);
int currState;
if (currValue > thres) {
currState = ABOVE_THRES;
}
else {
currState = BELOW_THRES;
}
if (prevState != currState) {
if (currState == ABOVE_THRES) {
Serial.println("UP");
}
else {
Serial.println("DOWN");
}
}
prevState = currState;
}