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 */
}