Hi there,
Java newbie here. I am experimenting with RFID and therefore learning how to give it commands in Java through Processing. I am currently using IF THEN commands and have successfully gotten the reader to switch content based on which chip interacts with it. However, I want the screen to return to a default video when the chip leaves the reader. I have tried a couple things, but the reader seems to be stuck on one chip's content until a new chip is placed on it, where I would like for it to immediately revert to a default screen when the chip is removed until the next chip is placed down. Can anyone see where I need to change this code to get that to happen? Thank you so very much.
import processing.serial.*;
Serial myPort;
String inString = "";
String RFID1 = "0200B916BC"; //Card 1 RFID
String RFID2 = "70006D389B"; //Card 2 RFID
String RFID3 = "010D5E1B7C"; //Card 3 RFID
String RFID4 = "840034486D"; //Card 3 RFID
PImage jpg;
boolean sketchFullScreen() {
return true;
}
void setup() {
size(1680, 1050);
myPort = new Serial(this, "COM3", 2400);
myPort.bufferUntil('\n');
jpg = loadImage("watercolor.jpg");
if (frame != null) {
frame.setResizable(true);
}
}
void draw() {
background(255);
image(jpg, width/1680, height/1050);
if (inString != null) {
fill(150, 255);
}
}
void serialEvent (Serial myPort)
{
String rfid = myPort.readStringUntil('\n'); // clean string
if (rfid == null)
{
rfid = "";
} else
{
rfid = trim(rfid);
}
// if current tag ignore
if (inString.equals(rfid))
{
return; // exits function
}
// new tag
inString = rfid;
if (RFID1.equals(inString))
{
jpg = loadImage("watercolor_01.jpg");
} else if (RFID2.equals(inString))
{
jpg = loadImage("watercolor_02.jpg");
} else if (RFID3.equals(inString))
{
jpg = loadImage("watercolor_03.jpg");
} else if (RFID4.equals(inString))
{
jpg = loadImage("watercolor_04.jpg");
} else
{
// unknown tag or no tag default
jpg = loadImage("watercolor.jpg");
}
}