Now arduino code is looking like:
void loop() {
for(pos = 60; pos < 120; pos += 1) // goes from 0 degrees to 180 degrees
{
delay(150); // waits 15ms for the servo to reach the position
Serial.print(",");
Serial.print(pos);
Serial.print(",");
// read the sensor:
int sensorValue0 = analogRead(A0);
// print the results:
Serial.print(sensorValue0);
Serial.print(",");
// read the sensor:
int sensorValue1 = analogRead(A1);
// print the results:
Serial.print(sensorValue1);
Serial.print(",");
// read the sensor:
int sensorValue2 = analogRead(A2);
// print the results:
Serial.print(sensorValue2);
Serial.print(",");
// read the sensor:
int sensorValue3 = analogRead(A3);
// print the results:
Serial.print(sensorValue3);
Serial.print(",");
// read the sensor:
int sensorValue4 = analogRead(A4);
// print the results:
Serial.print(sensorValue4);
Serial.print(",");
// read the sensor:
int sensorValue5 = analogRead(A5);
// print the results:
Serial.print(sensorValue5);
Serial.print(",");
int sensorValue6 = analogRead(A6);
Serial.print(sensorValue6);
Serial.println(",");
}
}
and part of processing code is looking like:
void draw() {
background(250);
delay(150);
// read the serial buffer:
String myString = myPort.readStringUntil('\n');
if (myString != null) {
myString = trim(myString);
// split the string at the commas
// and convert the sections into integers:
textFont(font, 15);
fill(0);
int sensors[] = int(split(myString, ','));
// print out the values you got:
for (int sensorNum = 0; sensorNum < sensors.length; sensorNum++) {
if (sensorNum == 0) {
text("Laser Value: " + sensors[sensorNum] + "\t", 50, 55);
}
if (sensorNum == 1) {
text("Position: " + sensors[sensorNum] + "\t", 50, 73);
}
if (sensorNum == 2) {
text(sensors[sensorNum], 100*sensorNum, 420);
}
if (sensorNum == 3) {
text(sensors[sensorNum] + "\t", 100*sensorNum, 420);
}
if (sensorNum == 4) {
text(sensors[sensorNum] + "\t", 100*sensorNum, 420);
}
if (sensorNum == 5) {
text(sensors[sensorNum] + "\t", 100*sensorNum, 420);
}
if (sensorNum == 6) {
text(sensors[sensorNum] + "\t", 100*sensorNum, 420);
}
if (sensorNum == 7) {
text(sensors[sensorNum] + "\t", 100*sensorNum, 420);
}
}
}
Axis();
Labels();
// PrintBars();
}
I cut out part which was written in void serialEvent(Serial myPort) {} and paste it under void draw(){}. Here I don't have no problems with writing value one over another and some other problems.
Thanks to PaulS.
Regards!
drejcek