We are about to switch to a new forum software. Until then we have removed the registration on this forum.
hi i'm trying to use rfid module with processing.
my plan is like when rfid tag is read , then link some url
but the problem is the rfid reader keep reading and keep page loaded.
how to solve this problem ? I would like loading url when rfid is read, not loading url when url already loaded
I think I should use boolean but I have no idea how to use it.
here is my code
import processing.serial.*;
Serial myPort; // Create object from Serial class
String dummy;
void setup()
{
size(200,200);
background(255);
myPort = new Serial(this, Serial.list()[8], 9600);
dummy=" ";
}
void draw()
{
byte[] inBuffer = new byte[7];
while (myPort.available() > 0) {
inBuffer = myPort.readBytes();
myPort.readBytes(inBuffer);
if (inBuffer != null) {
String myString = new String(inBuffer);
println(myString);
//println(myString.length());
//dummy=myString.substring(0,2);
//print(dummy);
dummy=myString;
if(dummy.equals("139") ==true) {
fill(0);
rect(0,0,150,150);
println("received 139");
link("http://allrecipes.com/search/default.aspx?ms=0&origin=Home+Page&rt=r&qt=i&wt=potato&pqt=i&fo=0");
}
if(dummy.equals("187") ==true) {
fill(150);
rect(0,0,150,150);
println("received 187");
link ("http://allrecipes.com/search/default.aspx?ms=0&origin=Home+Page&rt=r&qt=i&pqt=i&fo=0&wt=potato&w0=carrot&w1=onion");
}
}
}
Answers
General advice: in general, you can, and should, replace
if(dummy.equals("xxx") ==true) {
withif (dummy.equals("xxx")) {
Have a global boolean, eg. linkOpened.
When you call link(), set this variable to true.
And change the test to:
if (!linkOpened && dummy.equals("xxx")) {
Thus, you open a link only if not already done.
You can reset the variable to false after a while (use millis()).
yes I know what you mean
so do I have to declare boolean above ? like this :
boolean linkOpened = true;
and then
right??
about using millis() I should look into reference
thanks
linkOpened should be false (the default) initially: you haven't opened the link yet! Set it to true after the call to link().
ah okay I see !!
it's like this :