Hi Pieter,
Thanks again!
I was able to use your code, and have this mostly working :). I made a couple of small modifications, as I realized after posting that the original code I'm modifying actually has a routine for defining the variables "LEFT_KEY", "UP_KEY" etc - it's found at the end of the code.
The last thing I haven't been able to get working is the switch on the joystick. It works fine if I run a simple joystick sketch, so I think the wiring is ok, but not within the main program.
The code is a modification of a program created by Gary Liming used to drive a stepper motor for a step indexer application. The majority of the coding is beyond my level of understanding, so I'm sure there's a straightforward reason why the switch doesn't work! I tried to post the complete code, but it's larger than the limit allowed by the forum software. I've instead posted the section of code where the variables are defined - hopefully this is where the issue lies.
Thanks once more for your help!
Lee
int read_LCD_button() // routine to read the LCD's buttons
{
// int key_in;
int buttonstate;
//Added by LA
int xVal = analogRead (xPin);
int yVal = analogRead (yPin);
//End LA Edits
delay(ADSettleTime); // wait to settle
// key_in = analogRead(0); // read ADC once
buttonstate = digitalRead(SW_pin);
delay(ADSettleTime); // wait to settle
if (xVal > (center + threshold)) return RIGHT_KEY;
if (yVal > (center + threshold)) return UP_KEY;
if (yVal < (center - threshold)) return DOWN_KEY;
if (xVal < (center - threshold)) return LEFT_KEY;
if (buttonstate == HIGH) {return SELECT_KEY;
} else {return NO_KEY;
}