How to synchronize joystick with X-Sim

I am working on my final year project. According to my project teacher I built a arduino breadboard with 9 LEDs which represent the Pitch, Roll and Yaw. When I move the joystick to a certain angular one of the LEDs will light up to represent a certain degree. The difficult that I faced during the project is I have no idea how to synchronize the joystick with the X-Sim and arduino programming. All I know was to use serial monitor or real term to test the the LEDs on the arduino breadboard. The only program that i wrote was to change ASCII to INT. Please help.

int redPin = 3; // pin used for the LEDs
int greenPin = 2;
int yellowPin = 4;
int redPin2 = 7;
int greenPin2 = 6;
int yellowPin2 = 8;
int redPin3 = 10;
int greenPin3 =11;
int yellowPin3 = 9;
int final = 0;
int data;

void setup() {
// put your setup code here, to run once:
Serial.begin(9600); //initalize serial
pinMode(redPin, OUTPUT); // make the pins output
pinMode(greenPin, OUTPUT);
pinMode(yellowPin, OUTPUT);
pinMode(redPin2, OUTPUT);
pinMode(greenPin2, OUTPUT);
pinMode(yellowPin2, OUTPUT);
pinMode(redPin3, OUTPUT);
pinMode(greenPin3, OUTPUT);
pinMode(yellowPin3, OUTPUT);

digitalWrite(redPin, LOW);
digitalWrite(greenPin, LOW);
digitalWrite(yellowPin, LOW);
digitalWrite(redPin2, LOW);
digitalWrite(greenPin2, LOW);
digitalWrite(yellowPin2, LOW);
digitalWrite(redPin3, LOW);
digitalWrite(greenPin3, LOW);
digitalWrite(yellowPin3, LOW);
}

void pitch()
{
if(data == 127)
{
digitalWrite(redPin, HIGH);
digitalWrite(greenPin, LOW);
digitalWrite(yellowPin, LOW);
digitalWrite(redPin2, LOW);
digitalWrite(greenPin2, LOW);
digitalWrite(yellowPin2, LOW);
digitalWrite(redPin3, LOW);
digitalWrite(greenPin3, LOW);
digitalWrite(yellowPin3, LOW);
}

else if (data < 127)
{
digitalWrite(greenPin, HIGH);
digitalWrite(redPin, LOW);
digitalWrite(yellowPin, LOW);
digitalWrite(redPin2, LOW);
digitalWrite(greenPin2, LOW);
digitalWrite(yellowPin2, LOW);
digitalWrite(redPin3, LOW);
digitalWrite(greenPin3, LOW);
digitalWrite(yellowPin3, LOW);
}

else
{
digitalWrite(yellowPin, HIGH);
digitalWrite(greenPin, LOW);
digitalWrite(redPin, LOW);
digitalWrite(redPin2, LOW);
digitalWrite(greenPin2, LOW);
digitalWrite(yellowPin2, LOW);
digitalWrite(redPin3, LOW);
digitalWrite(greenPin3, LOW);
digitalWrite(yellowPin3, LOW);

}
}

void roll()
{
if(data == 127)
{
digitalWrite(redPin2, HIGH);
digitalWrite(greenPin2, LOW);
digitalWrite(yellowPin2, LOW);
digitalWrite(redPin, LOW);
digitalWrite(greenPin, LOW);
digitalWrite(yellowPin, LOW);
digitalWrite(redPin3, LOW);
digitalWrite(greenPin3, LOW);
digitalWrite(yellowPin3, LOW);

}

else if (data < 127)
{
digitalWrite(greenPin2, HIGH);
digitalWrite(redPin2, LOW);
digitalWrite(yellowPin2, LOW);
digitalWrite(redPin, LOW);
digitalWrite(greenPin, LOW);
digitalWrite(yellowPin, LOW);
digitalWrite(redPin3, LOW);
digitalWrite(greenPin3, LOW);
digitalWrite(yellowPin3, LOW);
}

else
{
digitalWrite(yellowPin2, HIGH);
digitalWrite(greenPin2, LOW);
digitalWrite(redPin2, LOW);
digitalWrite(redPin, LOW);
digitalWrite(greenPin, LOW);
digitalWrite(yellowPin, LOW);
digitalWrite(redPin3, LOW);
digitalWrite(greenPin3, LOW);
digitalWrite(yellowPin3, LOW);
}

}

void yaw()
{
if(data == 127)
{
digitalWrite(redPin3, HIGH);
digitalWrite(greenPin3, LOW);
digitalWrite(yellowPin3, LOW);
digitalWrite(redPin2, LOW);
digitalWrite(greenPin2, LOW);
digitalWrite(yellowPin2, LOW);
digitalWrite(redPin, LOW);
digitalWrite(greenPin, LOW);
digitalWrite(yellowPin, LOW);
}

else if (data < 127)
{
digitalWrite(greenPin3, HIGH);
digitalWrite(redPin3, LOW);
digitalWrite(yellowPin3, LOW);
digitalWrite(redPin2, LOW);
digitalWrite(greenPin2, LOW);
digitalWrite(yellowPin2, LOW);
digitalWrite(redPin, LOW);
digitalWrite(greenPin, LOW);
digitalWrite(yellowPin, LOW);
}

else
{
digitalWrite(yellowPin3, HIGH);
digitalWrite(greenPin3, LOW);
digitalWrite(redPin3, LOW);
digitalWrite(redPin2, LOW);
digitalWrite(greenPin2, LOW);
digitalWrite(yellowPin2, LOW);
digitalWrite(redPin, LOW);
digitalWrite(greenPin, LOW);
digitalWrite(yellowPin, LOW);
}
}

void loop()
{
// put your main code here, to run repeatedly:

data = Serial.read();
Serial.println(“Start”);
Serial.println(“Degree”);
delay(1000);

if(Serial.available() > 0) // don’t read unless
{
char ch1 = Serial.read();
char ch2 = Serial.read();
char ch3 = Serial.read();
char ch4 = Serial.read();
{

if (ch1 == ‘P’)
{
if (ch2 == ‘1’)
{
data = (ch2 - ‘0’) * 100 + (ch3 - ‘0’) * 10 + ch4 - ‘0’;
delay(1000);
}
else
{
data = (ch2 - ‘0’) * 10 + (ch3 - ‘0’);
}
Serial.print("data = ");
Serial.println(data, DEC);
delay(500);
pitch();
}

else if (ch1 == ‘R’)
{
if (ch2 == ‘1’)
{
data = (ch2 - ‘0’) * 100 + (ch3 - ‘0’) * 10 + ch4 - ‘0’;
delay(1000);
}
else
{
data = (ch2 - ‘0’) * 10 + (ch3 - ‘0’);
}
Serial.print("data = ");
Serial.println(data, DEC);
delay(500);
roll();
}

else if (ch1 == ‘Y’)
{
if (ch2 == ‘1’)
{
data = (ch2 - ‘0’) * 100 + (ch3 - ‘0’) * 10 + ch4 - ‘0’;
delay(1000);
}
else
{
data = (ch2 - ‘0’) * 10 + (ch3 - ‘0’);
}
Serial.print("data = ");
Serial.println(data, DEC);
delay(500);
yaw();
}
Serial.println(“end of loop”);
delay(1000);
}
}
}

Your code is long so it is not easy to read on-screen. Modify your Post and use the code button </>

so the code looks like this

. When you do that I will study it.

I don’t know what you mean by

I have no idea how to synchronize the joystick with the X-Sim

I can’t conceive of synchronizing a joystick with anything as I think of it as an input device. Also I have never come across a joystick whose position could be controlled by an Arduino.

…R

Hi,

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Can you please post a copy of your sketch, using code tags?
They are made with the </> icon in the reply Menu.
See section 7 http://forum.arduino.cc/index.php/topic,148850.0.html

Tom… :slight_smile:

The only program that i wrote was to change ASCII to INT.

So this isn't your program? You copied it from someone? Don't copy any more from them.

But it seems that this program has been successful in determining that the LEDs are wired up correctly. So that's a good start.

What is it that you really want to do? "Synchronise"? That doesn't mean anything by itself. Is there a real joystick or are you trying to display some data coming from a PC?

Please read Robin's "Planning and Implemeting an Arduino Program" It contains many good ideas to get you started on the track of writing a real program.

he difficult that I faced during the project is I have no idea how to synchronize the joystick with the X-Sim and arduino programming.

What is an X-Sim? Also, you missed #7 below:

http://forum.arduino.cc/index.php/topic,148850.0.html