Hi folks I'm trying to make a radar using servo and ultrasonic sensor and I have problem in visualizing data that I recieve from arduino. I want to make radar based on points that are drawn at the end of the line. I have got two values that I recieve from arduino: pos (position of the servo in deegres) and cm (distance from ultrasonic sensor). Data from The Arduino looks like that:
57.0servo position,49.0cm
58.0servo position,47.0cm
59.0servo position,30.0cm
60.0servo position,47.0cm
61.0servo position,47.0cm
62.0servo position,48.0cm
63.0servo position,47.0cm
and processing code:
import processing.serial.*;
int[] alphaVal = new int[100];
int[] distance2 = new int[100];
int lineSize = 4;
int linefeed = 10;
int carriageReturn = 13;
Serial myPort;
int sensorValue = 0;
float pos = 0;
float cm = 0;
void setup() {
size(800,800);
smooth();
background(0);
println(Serial.list());
myPort = new Serial(this, Serial.list()[0], 9600);
myPort.bufferUntil(carriageReturn);
for(int i=0; i<91; i++){
alphaVal[i] = 0;
}
}
void draw()
{
background(0); //clear the screen
if(pos<179){
point(400 + cm * cos(pos), 800 - cm * sin(pos));
}
if(pos >= 180){
background(0);
print(pos);
print(cm);
}
}
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) {
cm = float(items[1]);
pos = float(items[2]);
println(pos + "servo position" + "," +cm +"cm");
}
}
Can anybody help me with visualization of that data as I'm not a specialist. THANKS!!
Moderator edit: I can't help you with the visualisation of your data, but I can help with the visualisation of your code by putting in CODE TAGS.