servo and distance sensor problem to send data to processing

Hi folks! I'm quite new to arduino. I'm working on project with distance measurements and servos. I may say something like sonar. I have problem to send data from servo (its position) and distance from ultrasonic sensor to processing.

**This is my arduino code:**include <Servo.h>
const int trigPin = 42;
const int echoPin = 43;
Servo myservo;
Servo myservo1;

int pos = 0;
void setup()
{
Serial.begin(9600);
myservo.attach(10);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);

}

void loop()
{
long duration, cm;

for(pos = 5; pos < 180; pos += 1)
myservo.write(pos);

digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);

Serial.print("@");
Serial.print(cm);
Serial.print("");
Serial.print(pos);
Serial.println();
delay(50);
cm = microsecondsToCentimeters(duration);
}
for(pos = 180; pos>=10; pos-=1) // goes from 180 degrees to 0 degrees
{
myservo.write(pos);
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
Serial.print("@");
Serial.print(cm);
Serial.print("
");
Serial.print(pos);
Serial.println();
delay(50);

cm = microsecondsToCentimeters(duration);
}
}
long microsecondsToCentimeters(long microseconds)
{
return microseconds / 29 / 2;
}

And this is processing code:
import processing.serial.*;

int linefeed = 10; // linefeed in ASCII
int carriageReturn = 13; // carriage return in ASCII
Serial myPort; // The serial port
int sensorValue = 0; // the value from the sensor

float pos = 0;

float cm = 0;

void setup() {
println(Serial.list());

myPort = new Serial(this, Serial.list()[0], 9600);

myPort.bufferUntil(carriageReturn);
}

void draw() {
}

void serialEvent(Serial myPort) {

String myString = myPort.readStringUntil(linefeed);
if (myString != null) {
parseString(myString);
}
}

void parseString(String serialString) {
String items[] = (split(serialString, '*'));
if (items[0].equals("@") == true) {
pos = float(items[1]);
cm = float(items[3]);

println(pos + "," +cm);
}
}

 for(pos = 5; pos < 180; pos += 1) 
    myservo.write(pos);

Wouldn't a myservo.write (179); fulfill the same objective?

I have problem to send data from servo (its position) and distance from ultrasonic sensor to processing.

But you're not going to tell us what it is?
Could it be that you're always printing the previous loop's value for "cm"?

Please use CODE TAGS when posting code.

:grin:Yes, but I want servo to move step by step from one position to another.
It may be that i print position from last loop. But my problem is not proper work of arduino's program but sending data to processing. I'll focus on that issue later.

I think you're missing a ton of {} braces.
This

#include <Servo.h>
const int trigPin = 42;
const int echoPin = 43;
Servo myservo;
 
void setup()
{
  Serial.begin(9600);
  myservo.attach(10); 
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
}
 
 
void loop()
{
  for(int pos = 5; pos < 180; pos += 1) 
  {
    myservo.write(pos);       
   
    digitalWrite(trigPin, LOW);
    delayMicroseconds(2);
    digitalWrite(trigPin, HIGH);
    delayMicroseconds(10);
    digitalWrite(trigPin, LOW);
    long duration = pulseIn(echoPin, HIGH);
    long cm = microsecondsToCentimeters(duration);   
 
    Serial.print("@");
    Serial.print(cm);
    Serial.print("*");
    Serial.print(pos);
    Serial.println();
    delay(50);
  }
}
long microsecondsToCentimeters(long microseconds)
{
    return microseconds / 29 / 2;
}

at least compiles.

But my problem is not proper work of arduino's program

Your Arduino code doesn't even compile, so it cannot run, and cannot therefore be said to "not work"

Thanks for that. Works perfectly. Can you help me sending this to processing?

Can you help me sending this to processing?

What would "this" be? That code is ALREADY writing to the serial port. Processing can read the data.