I am doing a project where I use RFID readers for location. I am using Processing to manage data obtained from the readers.
The problem is that I do not know how to display information "no tag" when the tag is removed from the reader. Right now the name of the tag keeps on being displayed even after the tag is removed - until another tag appears within reader's range.
Can someone please help me solve that issue?
here is my current code:
import processing.serial.*;
Serial myPort1;
Serial myPort2;
String sensorReading1="";
String sensorReading2="";
PFont font;
PImage bg;
void setup() {
size(2290,1433);
bg = loadImage("map.jpg");
myPort1 = new Serial(this, "COM4", 9600);
myPort1.bufferUntil('\n');
myPort2 = new Serial(this, "COM5", 9600);
myPort2.bufferUntil('\n');
font = createFont(PFont.list()[2],52);
textFont(font);
}
void draw() {
background(bg);
writeText2("Reader2: \t"+sensorReading2);
writeText1("Reader1: \t"+sensorReading1);
}
void serialEvent (Serial myPort){
while(myPort.available() >0){
if(myPort == myPort1) {
sensorReading1 = myPort1.readString();
sensorReading1 = trim(sensorReading1);
}
if(myPort == myPort2) {
sensorReading2 = myPort2.readString();
sensorReading2 = trim (sensorReading2);
}
}
}
void writeText1(String textToWrite1){
fill(204, 102, 0);
rect(width/20, height/5, 55, 55);
text(textToWrite1, width/20, height/5); }
void writeText2(String textToWrite2){
text(textToWrite2, width/20, height/2); }