i need some help with a serial code

I am making two servos point at a spot using 1 serial port
but my code is not working please can you give me some idea where i have go wrong

#include <Servo.h>
int pingPin = 3;
Servo x;
Servo y;
int X = 0;
int Y = 0;
int a = 0;

void setup()
{
Serial.begin(9600);
x.attach(10);
y.attach(9);
}

void loop()
{
a = Serial.read();
if (a>=181){
Y=a-181;
y.write(Y);
}
else {if (a<=180){
X=a;
x.write(X);
}}

if (a==361){
long duration, inches, cm;
pinMode(pingPin, INPUT);
duration = pulseIn(pingPin, HIGH);
inches = microsecondsToInches(duration);
Serial.print(inches);
Serial.println();

}}
long microsecondsToInches(long microseconds)
{
return microseconds / 147/ 2;
}

void loop() 
{
  [glow]if ( Serial.available() > 0 )[/glow]
  [glow]{[/glow]
a = Serial.read();
if (a>=181){
Y=a-181;
y.write(Y);
}
else {if (a<=180){
X=a;
x.write(X);
}
  [glow]}[/glow]
}

thank you but it has not worked :( here is my prosesing script that works with it

import processing.serial.*; int Y; Serial myPort; // Create object from Serial class int D=1000; int X; void setup() { size(180, 180); Serial.list(); String portName = Serial.list()[10]; myPort = new Serial(this, portName, 9600); } void draw() { delay(D); X=mouseX; myPort.write(X); println(mouseX); delay(D); myPort.write(Y); Y=mouseY+181; println(mouseY); }

my code is not working please can you give me some idea where i have go wrong

What does "not working" actually mean?

the X and Y servos are runing one at a time when my mouse is at X:100 Y:50 it will move one of the servos to 100 then to 50 i want it to move one to 100 and the other to 50

That explanation doesn’t really make any sense to me out of the context of your project.

What is sending the serial characters? A PC or another device? I ask because you have things like (a>181). So that means if you are sending characters from the PC, you need to be sending the ASCII character that is associated with 181. (In other words, your code won’t work if you are sending numeric strings like “181”).

servo x uses the serial to get a number between 0 and 180 were as servo y gets a number between 181 and 361 then it takes away 181 which gives i a number between 0 and 180 so the servo can run

managed to get it to work

the problem was the serisl only allows a value up to 255 and then it goes back to 1 ;D ;D

only allows a value up to 255 and then it goes back to 1

sp. "goes back to zero"