Hi !
Description
I have some problem while doing my project.
I am trying to draw radar with incoming values which is variable(value from two potentiometer)
I got two variable value from my sensor and its form is like “x,y.”.
And I’m trying to draw a line.; ------ line(x,y,x(previous x), y(previous))
Also, I would like to save its log file.
This is Arduino code for potentiometer :
int valx = 0;
int valy = 0;void setup ()
{
Serial.begin(9600);
}void loop() {
valx = analogRead(A0);
valy = analogRead(A1);Serial.print(valx);
Serial.print(“,”);
Serial.print(valy);
Serial.println(“.”);
delay(1000);
}
This is Processing code I write:
import processing.serial.*;
PrintWriter output;
Serial myPort;
String myString=null;
float x=0;
float y=0;
float pre_data=0;
float inByte = 0;
void setup () {
size (1000,1000);
myPort = new Serial(this, “COM16”, 9600);
output = createWriter(“CNSAT radar log file.txt”);}
void draw(){
translate(width/2,height/2);
drawrader();
drawtarget();
line(x, y-pre_data, x, y - inByte);
if (x>= width) {
println(“Out of range”)}else {
}
pre_data = inByte;
}void drawradar() {
background(0);
noFill();
strokeWeight(2);
stroke(98,245,31);
ellipse(0,0,900,900);
ellipse(0,0,700,700);
ellipse(0,0,500,500);
ellipse(0,0,300,300);
ellipse(0,0,100,100);
strokeWeight(1);
line(-400,-400,400, 400);
line(400,-400,-400,400);
line(0,-400,0,400);
line(-400,0,400,0);
textAlign(RIGHT);
text(“10cm”,50,0);
text(“20cm”,150,0);
text(“30cm”,250,0);
text(“40cm”,350,0);
text(“50cm”,450,0);
}void drawtarget() {
fill(0,7);
rect(-400,400,width, height);
strokeWeight(3);
stroke(255,0,0);
}void SerialEvent(Serial p ) {
if(myPort.available() >0){
try{
myString = p.readStringUntil(‘.’);
if (myString != null) {
myString = trim(myString);
println(myString);
Stringlist = split( myString, ‘,’);//list 1 and list 2 + . is seperated
x = float(list [0]);
y = float(list [1].replace(“,”,“”));
output.println(x+“,”+“,”+y+“,”);
ellipse(x,y,5,5);
line(x,y,4,4);
}
}catch(Exception e ) {
}
}
}void keyPressed() {
output.flush();
output.close();
}
So, I did research about if and write my code.
However, unfortunately, it failed. (value is incoming but it does not draw line in rader)
And these are Three Questions I have
- Is my code is correct to draw radar?
- Is my code is correct to save x,y value?
If you have some points take makes you difficult to understand my code please leave message.
I really appreciate for your help! `