Is this better?
No, not really.
double saveY, saveX, state;
So, saveY is a global variable.
test(saveY);
You pass it to this function.
int test(int saveY)
{
Serial.write(0xFE); //command flag
Serial.write(192); //position
saveY=Yangle;
Whereupon you stomp on it.
test() is a lousy name for a function. A function's name should tell the caller EXACTLY what to expect the function to do. digitalRead(), analogWrite(), etc. don't require much thought, and no code reading, to figure out what they do.
What, exactly, is test() supposed to do? If it's intent is to store a value when a switch is pressed, then, it should have "save" somewhere in it's name. The value to be saved should be passed to the function, not where to save the value.