OK, if you want an hysteresis you would do something like this
const int lowToHighThreshold = 600;
const int HighToLowThreshold = 400;
const byte joystickPin = A0;
byte joystickState = LOW;
const byte outputPin = 13;
void setup() {
pinMode(outputPin, OUTPUT);
digitalWrite(outputPin, joystickState);
}
void loop() {
if (joystickState == LOW) {
if (analogRead(joystickPin) > lowToHighThreshold) {
digitalWrite(outputPin, HIGH);
joystickState = HIGH;
}
} else {
if (analogRead(joystickPin) < HighToLowThreshold) {
digitalWrite(outputPin, LOW);
joystickState = LOW;
}
}
}
(typed here so mind typos)