import processing.serial.*; // Importa as bibliotecas para comunicação de Seriew
import java.awt.event.KeyEvent; // Importa as bibliotecas para ler a informação da entrada de serie
import java.io.IOException;
Serial myPort; // define o objeto Serial
// define as variaveis
String angle="";
String distance="";
String data="";
String noObject;
float pixsDistance;
int iAngle, iDistance;
int index1=0;
int index2=0;
PFont orcFont;
void setup() {
size (1280, 720); // **Mudar isto para a sua resolução**
smooth();
myPort = new Serial(this,"COM3", 9600); // Começa a comunicação Serie
myPort.bufferUntil('.'); // Lê o Serial Monitor até ao ponto final
orcFont = loadFont("OCRAExtended-30.vlw");
}
void draw() {
fill(98,245,31);
textFont(orcFont);
// Simula o movimento das linhas
noStroke();
fill(0,4);
rect(0, 0, width, height-height*0.065);
fill(98,245,31); // green color
// Chama as funções Radar, line, Object, Text
drawRadar();
drawLine();
drawObject();
drawText();
}
void serialEvent (Serial myPort) { // Começa a ler a informação de Serie
// lê a informação de Serie até ao caracter '.', esta informação é atribuida a uma string chamada "data".
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());
// Converte as variaveis string em Integer
iAngle = int(angle);
iDistance = int(distance);
}
void drawRadar() {
pushMatrix();
translate(width/2,height-height*0.074); // Move as coordenadas iniciais para outro local
noFill();
strokeWeight(2);
stroke(98,245,31);
// Desenha os semicirculos
arc(0,0,(width-width*0.0625),(width-width*0.0625),PI,TWO_PI);
arc(0,0,(width-width*0.27),(width-width*0.27),PI,TWO_PI);
arc(0,0,(width-width*0.479),(width-width*0.479),PI,TWO_PI);
arc(0,0,(width-width*0.687),(width-width*0.687),PI,TWO_PI);
// Desenha as linhas dos angulos
line(-width/2,0,width/2,0);
line(0,0,(-width/2)*cos(radians(30)),(-width/2)*sin(radians(30)));
line(0,0,(-width/2)*cos(radians(60)),(-width/2)*sin(radians(60)));
line(0,0,(-width/2)*cos(radians(90)),(-width/2)*sin(radians(90)));
line(0,0,(-width/2)*cos(radians(120)),(-width/2)*sin(radians(120)));
line(0,0,(-width/2)*cos(radians(150)),(-width/2)*sin(radians(150)));
line((-width/2)*cos(radians(30)),0,width/2,0);
popMatrix();
}
void drawObject() {
pushMatrix();
translate(width/2,height-height*0.074); // Move as coordenadas iniciais para outro local
strokeWeight(9);
stroke(255,10,10); // red color
pixsDistance = iDistance*((height-height*0.1666)*0.025); // cobre a distancia entre o sensor e o objeto
// limiting the range to 40 cms
if(iDistance40) {
noObject = "Out of Range";
}
else {
noObject = "In Range";
}
fill(0,0,0);
noStroke();
rect(0, height-height*0.0648, width, height);
fill(98,245,31);
textSize(25);
text("10cm",width-width*0.3854,height-height*0.0833);
text("20cm",width-width*0.281,height-height*0.0833);
text("30cm",width-width*0.177,height-height*0.0833);
text("40cm",width-width*0.0729,height-height*0.0833);
textSize(40);
text("Object: " + noObject, width-width*0.875, height-height*0.0277);
text("Angle: " + iAngle +" °", width-width*0.48, height-height*0.0277);
text("Distance: ", width-width*0.26, height-height*0.0277);
if(iDistance
Read the full article