0% found this document useful (0 votes)
17 views

Code For Displaying The Radar

radar system code

Uploaded by

Sumit Chouhan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

Code For Displaying The Radar

radar system code

Uploaded by

Sumit Chouhan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

/*Ultrasonic radar system.

*Run the following code a second time.


*created by Indian wings rc.
*Read the code below and use it for any of your creations.
*/

//import following libraries


import processing.serial.*;
import java.awt.event.KeyEvent;
import java.io.IOException;

Serial myport;//create serial object

PFont f;
int Angle, Distance;
String angle="";
String distance="";
String data;
int index1=0;
int index2=0;
float pixsDistance;

void setup() {
size(1250, 700);//screen size
smooth();
printArray(PFont.list());//show font list your computer
f = createFont("David Bold", 30);//font name and size
textFont(f);

String portName = Serial.list()[0];//set COM port


myport = new Serial(this, portName, 9600);
myport.bufferUntil('.');
}

void draw() {

noStroke();
fill(0, 10);
rect(0, 0, width, 700);
fill(98, 245, 31);
greenmesh();
radararea();
words();
greenLine();
redline();
}
//get ardunio board serial values
void serialEvent (Serial myport) {
data = myport.readStringUntil('.');
data = data.substring(0, data.length()-1);

index1 = data.indexOf(",");
angle= data.substring(0, index1);
distance= data.substring(index1+1, data.length());

// converts the String variables into Integer


Angle = int(angle);
Distance = int(distance);
}
//Half circle and lines
void radararea() {
pushMatrix();
translate(625, 680);
noFill();
strokeWeight(2);
stroke(98, 245, 31);
// draws the arc lines
arc(0, 0, 1150, 1150, PI, TWO_PI);
arc(0, 0, 850, 850, PI, TWO_PI);
arc(0, 0, 550, 550, PI, TWO_PI);
arc(0, 0, 250, 250, PI, TWO_PI);
// draws the angle lines
line(-450, 0, 450, 0);
line(0, 0, -600*cos(radians(30)), -600*sin(radians(30)));
line(0, 0, -600*cos(radians(60)), -600*sin(radians(60)));
line(0, 0, -600*cos(radians(90)), -600*sin(radians(90)));
line(0, 0, -600*cos(radians(120)), -600*sin(radians(120)));
line(0, 0, -600*cos(radians(150)), -600*sin(radians(150)));
line(-960*cos(radians(30)), 0, 960, 0);
popMatrix();
}

//Green box net


void greenmesh() {
stroke(98, 245, 31);
strokeWeight(0.1);
for (int x=0; x<=700; x+=5) {
line(0, x, width, x);
}
for (int y=0; y<=1250; y+=5) {
line(y, 0, y, height);
}
}

//print text
void words() {
fill(98, 245, 31);
text("180'", 10, 670);
fill(98, 245, 31);
text("0'", 1210, 670);
fill(98, 245, 31);
text("30'", 1160, 380);
fill(98, 245, 31);
text("60'", 940, 160);
fill(98, 245, 31);
text("90'", 615, 70);
fill(98, 245, 31);
text("120'", 310, 150);
fill(98, 245, 31);
text("150'", 80, 370);
fill(255);
text("Indian Wings RC Radar system", 20, 30);
fill(255);
text("Angle -- "+Angle+" '", 20, 60);
fill(255);
text("Distance -- "+Distance+" cm", 20, 90);
}
//Drawing green lines
void greenLine() {
pushMatrix();
strokeWeight(7);
stroke(30, 250, 60);//green color
translate(625, 680);
line(0, 0, 600*cos(radians(Angle)), -600*sin(radians(Angle)));
popMatrix();
}
//Drawing red lines
void redline() {
pushMatrix();
translate(625, 680);
strokeWeight(7);
stroke(255, 10, 10); //red color
pixsDistance = Distance*22.5;
// limiting the range to 40 cm
if (Distance<40) {
line(pixsDistance*cos(radians(Angle)), -pixsDistance*sin(radians(Angle)),
600*cos(radians(Angle)), -600*sin(radians(Angle)));
}
popMatrix();
}

You might also like