Help needed with a remotely controlled robot

Hello experts ,

Here is what I am trying to do … I am controlling 2 dc motors and 2 linear actuators using an Arduino Mega board with an Ethernet shield . The board is then connected to a LINKSYS router (running as bridge) through the ethernet cable . The bridge is bridged to another LINKSYS router which is creating a WIFI network. On the other hand, I am trying to control all this using a joystick connected to a laptop. Therefore , there must be some sort of a software running on the laptop to map the joystick position and send that to the Arduino board through the wireless connection. I am currently using AUTOHOTKEY to map the position of the joystick to a corresponding keyboard button.

Here is how it works :

1-The AutoHotkey is running a script that will monitor the position of the joystick with respect to X and Y axis, for example it would say something like :

if X>10
Send (1);
and what is this doing is sending a Ascii code of the digit one every time the condition of (the joystick is pushed to the left 10% before the origin point) x>10% of the total X axis
Similarly ,
if 10>y>20

2- The character is sent to the serial port and received by the Arduino code to do a certain action , for example

if char(inByte == ‘1’)
{digitalwrite MotorPinLeft (High)} ;

Now, my question : Is there any other way of doing the same thing using a different client on the laptop since I am not satisfied with AutoHotKey performance ?

Also, If I want to write a line to check if connection between client and server is lost , how do I do that?

I will post entire code here for more details… Please feel free to ask question if something isn’t clear … Any help will be appreciated

Thanks

The code:
/*
Lunabot Motor Control

Characters are accepted via telnet connection and interpretted as
motor control Commanda

created 18 Dec 2009
by David A. Mellis
modified 30 Dec 2010
by Bill Bagdon

*/

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

// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network.
// gateway and subnet are optional:
byte mac = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip = {
192,168,1, 177 };
byte gateway = {
192,168,1, 254 };
byte subnet = {
255, 255, 0, 0 };

#define MotorPinLeft 9
#define MotorPinRight 6

#define ArmUp 28
#define ArmDown 22
#define BucketUp 25
#define BucketDown 27

// telnet defaults to port 23
Server server(23);
boolean gotAMessage = false; // whether or not you got a message from the client yet

void setup() {
pinMode(MotorPinLeft, OUTPUT);
pinMode(MotorPinRight, OUTPUT);
pinMode(ArmUp, OUTPUT);
pinMode(ArmDown, OUTPUT);
pinMode(BucketUp, OUTPUT);
pinMode(BucketDown, OUTPUT);

//initialize the ethernet device
Ethernet.begin(mac, ip, gateway, subnet);
// start listening for clients
server.begin();
// open the serial port
Serial.begin(9600);
}

void loop() {
// wait for a new client:
Client client = server.available();

// when the client sends the first byte, say hello:
if (client) {
if (!gotAMessage) {
Serial.println(“We have a new client”);
client.println(“Welcome”);
gotAMessage = true;
}

// read the bytes incoming from the client:
char inByte = client.read();
move(inByte);
// echo the bytes back to the client:
server.write(inByte);
// echo the bytes to the server as well:
Serial.print(inByte);
}

}

void move(char inByte){
if (inByte == ‘x’){
digitalWrite(ArmUp, HIGH);
digitalWrite(ArmDown, LOW); //1 0
}
else if (inByte == ‘v’){
digitalWrite(ArmUp, LOW);
digitalWrite(ArmDown, HIGH); //0 1
}
else if (inByte == ‘n’){
digitalWrite(ArmUp, LOW);
digitalWrite(ArmDown, LOW); // 0 0
}
else if (inByte == ‘c’){
digitalWrite(BucketUp, HIGH);
digitalWrite(BucketDown, LOW); //1 0
}
else if (inByte == ‘b’){
digitalWrite(BucketUp, LOW);
digitalWrite(BucketDown, HIGH); //0 1
}
else if (inByte == ‘n’){
digitalWrite(BucketUp, LOW);
digitalWrite(BucketDown, LOW); //0 0
}
else if (inByte == ‘9’){
analogWrite(MotorPinLeft, 140); // 1
}
else if (inByte == ‘8’){
analogWrite(MotorPinLeft, 151); // 2
}
else if (inByte == ‘7’){
analogWrite(MotorPinLeft, 162); // 3
}
else if (inByte == ‘6’){
analogWrite(MotorPinLeft, 173); // 4 // CLOCKWISE
}
else if (inByte == ‘5’){
analogWrite(MotorPinLeft, 188); // 5 // NEUTRAL
}
else if (inByte == ‘4’){
analogWrite(MotorPinLeft, 204); // 6 // COUNTER CLK
}
else if (inByte == ‘3’){
analogWrite(MotorPinLeft, 215); // 7
}
else if (inByte == ‘2’){
analogWrite(MotorPinLeft, 226); // 8
}
else if (inByte == ‘1’){
analogWrite(MotorPinLeft, 237); // 9
}

if (inByte == ‘9’){
analogWrite(MotorPinRight, 140); // 1
}
else if (inByte == ‘8’){
analogWrite(MotorPinRight, 151); // 2
}
else if (inByte == ‘7’){
analogWrite(MotorPinRight, 162); // 3
}
else if (inByte == ‘6’){
analogWrite(MotorPinRight, 173); // 4 // CLOCKWISE
}
else if (inByte == ‘5’){
analogWrite(MotorPinRight, 188); // 5 // NEUTRAL
}
else if (inByte == ‘4’){
analogWrite(MotorPinRight, 204); // 6 // COUNTER CLK
}
else if (inByte == ‘3’){
analogWrite(MotorPinRight, 215); // 7
}
else if (inByte == ‘2’){
analogWrite(MotorPinRight, 226); // 8
}
else if (inByte == ‘1’){
analogWrite(MotorPinRight, 237); // 9
}
if (inByte == ‘a’){
analogWrite(MotorPinLeft, 140); // 1
}
else if (inByte == ‘s’){
analogWrite(MotorPinLeft, 151); // 2
}
else if (inByte == ‘d’){
analogWrite(MotorPinLeft, 162); // 3
}
else if (inByte == ‘f’){
analogWrite(MotorPinLeft, 173); // 4 // CLOCKWISE
}
else if (inByte == ‘g’){
analogWrite(MotorPinLeft, 188); // 5 // NEUTRAL
}
else if (inByte == ‘h’){
analogWrite(MotorPinLeft, 204); // 6 // COUNTER CLK
}
else if (inByte == ‘j’){
analogWrite(MotorPinLeft, 215); // 7
}
else if (inByte == ‘k’){
analogWrite(MotorPinLeft, 226); // 8
}
else if (inByte == ‘l’){
analogWrite(MotorPinLeft, 237); // 9
}

if (inByte == ‘l’){
analogWrite(MotorPinRight, 140); // 1
}
else if (inByte == ‘k’){
analogWrite(MotorPinRight, 151); // 2
}
else if (inByte == ‘j’){
analogWrite(MotorPinRight, 162); // 3
}
else if (inByte == ‘h’){
analogWrite(MotorPinRight, 173); // 4 // CLOCKWISE
}
else if (inByte == ‘g’){
analogWrite(MotorPinRight, 188); // 5 // NEUTRAL
}
else if (inByte == ‘f’){
analogWrite(MotorPinRight, 204); // 6 // COUNTER CLK
}
else if (inByte == ‘d’){
analogWrite(MotorPinRight, 215); // 7
}
else if (inByte == ‘s’){
analogWrite(MotorPinRight, 226); // 8
}
else if (inByte == ‘a’){
analogWrite(MotorPinRight, 237); // 9
}
}

Send (a);

Ow! My scrolling finger hurts. When posting code, please use the # (Code) icon on the editor's toolbar.

(Not sure all those "else"s are strictly necessary)

AWOL: Ow! My scrolling finger hurts. When posting code, please use the # (Code) icon on the editor's toolbar.

(Not sure all those "else"s are strictly necessary)

Sorry , I am new to forums ! You probably right, all these "elses " aren't necessary .. I am pretty sure there is a better way to code this.. I just don't know it .. Please let me know if you know it Thanks

Well, you could consider the switch/case construct. Don't forget to use 'break'. Though, for that number of actions, I'd probably consider using a simple interpreter and table of characters/pins/actions.