Joystick function to write to servo

How would I retrieve the joystick value from X and Y in this sketch and write them to two servos?

#include <SPI.h>
#include <Ethernet.h>
#include <SD.h>
#include <IOSController.h>

/* Start your code (defines) */
/* End your code */

/*
 *
 * Initialize the Ethernet server library
 */
byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED}; 

IPAddress ip(192,168,1,145);
IPAddress gateway(192,168,1,2);
IPAddress subnet(255,255,255,0);

EthernetServer server(80);

/*
 *
 * Prototypes of IOSController's callbacks
 *
 *
 */
void doWork();
void doSync(char *variable);
void processIncomingMessages(char *variable, char *value);
void processOutgoingMessages();
void processAlarms(char *variable);
void deviceConnected();
void deviceDisconnected();

/*
 *
 * IOSController Library initialization
 *
 */
IOSController iosController(&server,&doWork,&doSync,&processIncomingMessages,&processOutgoingMessages,&deviceConnected,&deviceDisconnected);

/******* Start Global Variable for Widgets *******/

/******* End Global Variable for Widgets *******/

void setup() {
  
  Serial.begin(9600);
  
  

  Ethernet.begin(mac, ip, subnet, gateway);  
  server.begin();

  /* Start your code (setup) */
  /* End your code */
}

void loop() {
  
  iosController.loop(500);
}

/**
*
*
* This function is called periodically and its equivalent to the standard loop() function
*
*/
void doWork() {



  /* Start your code (doWork) */
  /* End your code */
}

/**
*
*
* This function is called when the ios device connects and needs to initialize the position of switches and knobs
*
*/
void doSync (char *variable) {



  /* Start your code (doSync) */
  /* End your code */
}

/**
*
*
* This function is called when a new message is received from the iOS device
*
*/
void processIncomingMessages(char *variable, char *value) {


  if (strcmp(variable,"JoystickX") == 0) {

    if (atoi(value)>0) {

      joystickJoystickMoveRightCallback(atoi(value));
    }
    else {

      joystickJoystickMoveLeftCallback(-atoi(value));
    }
  }

  if (strcmp(variable,"JoystickY") == 0) {

    if (atoi(value)>0) {

      joystickJoystickMoveBackwardCallback(atoi(value));
    }
    else {

      joystickJoystickMoveForwardCallback(-atoi(value));
    }
  }


  /* Start your code (processIncomingMessages) */
  /* End your code */
}

/**
*
*
* This function is called periodically and messages can be sent to the iOS device
*
*/
void processOutgoingMessages() {



  /* Start your code (processOutgoingMessages) */
  /* End your code */
}

void deviceConnected () {

  /* Start your code (deviceConnected) */
  /* End your code */
}

void deviceDisconnected () {

  /* Start your code (deviceDisconnected) */
  /* End your code */
}


/* Widgets synchronization callbacks */


/* Widgets operations callbacks */

void joystickJoystickMoveRightCallback(int value) {

  /* Start your code (joystickJoystickMoveRightCallback) */
  /* End your code */
}

void joystickJoystickMoveLeftCallback(int value) {

  /* Start your code (joystickJoystickMoveLeftCallback) */
  /* End your code */
}

void joystickJoystickMoveForwardCallback(int value) {

  /* Start your code (joystickJoystickMoveForwardCallback) */
  /* End your code */
}

void joystickJoystickMoveBackwardCallback(int value) {

  /* Start your code (joystickJoystickMoveBackwardCallback) */
  /* End your code */
}



/**** User Functions *****/

/* Start your code (User Functions) */
/* End your code */

I am trying to do it here, for instance, but to no avail. The joystick should be producing a 0-1023 value in each direction.

I am trying to use:

servoPos = map(atoi(value), 0, 1023, 0, 180);

in here:

void joystickJoystickMoveBackwardCallback(int value) {

  /* Start your code (joystickJoystickMoveBackwardCallback) */
  /* End your code */
}

Do you have code that only reads the joystick and does it work?
Or code that reads a potentiometer?

Is the joystick an analog stick?

The above is code generated by Arduino Manager's code generator for their ipad app interface. The ipad "widget" for joystick will generate a 0-1023 value for each of the 4 directions. Positive in one direction and negative in the other. One in the x axis and the other in y.

From the manual:

the Arduino code, messages received has the following format:

Variable Value Range Description
X -1023 - +1023 0: neutral position
-1023: leftmost position
+1023: rightmost position
Y -1023 - +1023 0: neutral position
-1023: uppermost position
+1023: lowermost position
where is the label assigned to the widget.

Then, this simple code can be used to catch the messages from the widget:

if (strcmp(variable,”Joy1X”)==0) {
}
if (strcmp(variable,”Joy1X”)==0) {
}

I'm not going to dig in that library so I can't say what's missing but these are just some of the functions that look like you're maybe supposed to fill in?

/* Widgets operations callbacks */

void joystickJoystickMoveRightCallback(int value) {

  /* Start your code (joystickJoystickMoveRightCallback) */
  /* End your code */
}

void joystickJoystickMoveLeftCallback(int value) {

  /* Start your code (joystickJoystickMoveLeftCallback) */
  /* End your code */
}

void joystickJoystickMoveForwardCallback(int value) {

  /* Start your code (joystickJoystickMoveForwardCallback) */
  /* End your code */
}

void joystickJoystickMoveBackwardCallback(int value) {

  /* Start your code (joystickJoystickMoveBackwardCallback) */
  /* End your code */
}

You could maybe check if the input is getting through by printing value in this fuinction as below.
We call these lines debug prints and comment them out or remove them in the final code or put them in #ifdef blocks that I am not explaining here. For now, just pick up on printing data or symbols to see what your code is doing as a way to debug it.

void processIncomingMessages(char *variable, char *value) {


  if (strcmp(variable,"JoystickX") == 0) {

    if (atoi(value)>0) {

Serial.print( "\n JoystickX " );
Serial.println( value );

      joystickJoystickMoveRightCallback(atoi(value));
    }
    else {

Serial.print( "\n JoystickX " );
Serial.println( value );

      joystickJoystickMoveLeftCallback(-atoi(value));
    }
  }

  if (strcmp(variable,"JoystickY") == 0) {

    if (atoi(value)>0) {

Serial.print( "\n JoystickY " );
Serial.println( value );

      joystickJoystickMoveBackwardCallback(atoi(value));
    }
    else {

Serial.print( "\n JoystickY " );
Serial.println( value );

      joystickJoystickMoveForwardCallback(-atoi(value));
    }
  }


  /* Start your code (processIncomingMessages) */
  /* End your code */
}

Thanks. Good suggestion to get a view of what is going on inside the program.

I tried it, and the x and y values seem to just ramp up and down by the count of 2 or 3 units, until they either reach zero and reverse, or 1023 and go back down. Doesn't seem to be any relationship between this and the joystick standing still, centred, or moving. Bummer.

I will try ditching the code from the code generator, and instead use the code from the manual.

See if you can just capture the text from the pad and print lines of that to verify correct operation between the two.
Simplify and isolate the working points and soon enough the bugs will be apparent.

Anyone out there ever use Arduino Manager's joystick function?

Servo/pot test code for use with a joystick.

//zoomkat dual pot/servo test 12-29-12
//view output using the serial monitor

#include <Servo.h> 
Servo myservoS1;
Servo myservoS2;

int potpinS1 = 0;  //analog input pin A0
int potpinS2 = 1;

int newvalS1, oldvalS1;
int newvalS2, oldvalS2;

void setup() 
{
  Serial.begin(9600);  
  myservoS1.attach(2);  
  myservoS2.attach(3);
  Serial.println("testing dual pot servo");  
}

void loop() 
{ 
  newvalS1 = analogRead(potpinS1);           
  newvalS1 = map(newvalS1, 0, 1023, 0, 179); 
  if (newvalS1 < (oldvalS1-2) || newvalS1 > (oldvalS1+2)){  
    myservoS1.write(newvalS1);
    Serial.print("1- ");
    Serial.println(newvalS1);
    oldvalS1=newvalS1;
  }

  newvalS2 = analogRead(potpinS2);
  newvalS2 = map(newvalS2, 0, 1023, 0, 179);
  if (newvalS2 < (oldvalS2-2) || newvalS2 > (oldvalS2+2)){  
    myservoS2.write(newvalS2);
    Serial.print("2- ");    
    Serial.println(newvalS2);
    oldvalS2=newvalS2;
  }
  delay(50); //slow down looping to better read serial monitor 
}