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 axisSimilarly ,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

// 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); }

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 itThanks

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.

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.Do not send technical questions via personal messaging - they will be ignored.