I'm trying to play music based on which RFID card is over the reader. Everything is working properly, the cards are being recognized, and I can get the music to play if it's not within the if statement.
When I put the card with tag 1600a8c21c over the reader, it is recognized and prints the card tag, but the if statement does not execute.
I would have assumed that tag == songTag when the card is over the reader, but for some reason this is not the case. The relevant if statement is at the very bottom.
Thanks for any help
- import com.phidgets.*;
- import com.phidgets.event.*;
- import ddf.minim.*;
- AudioPlayer player;
- Minim minim;
- RFIDPhidget rfid = null;
- PFont font;
- String tag="";
- boolean playing = false;
- String songTag = "1600a8c21c";
- void setupReader() {
- try {
- rfid = new RFIDPhidget();
- rfid.addAttachListener(new AttachListener() {
- public void attached(AttachEvent ae)
- {
- try
- {
- ((RFIDPhidget)ae.getSource()).setAntennaOn(true);
- ((RFIDPhidget)ae.getSource()).setLEDOn(true);
- }
- catch (PhidgetException ex) {
- }
- println("attachment of " + ae);
- }
- }
- );
- rfid.addDetachListener(new DetachListener() {
- public void detached(DetachEvent ae) {
- System.out.println("detachment of " + ae);
- }
- }
- );
- rfid.addErrorListener(new ErrorListener() {
- public void error(ErrorEvent ee) {
- System.out.println("error event for " + ee);
- }
- }
- );
- rfid.addTagGainListener(new TagGainListener()
- {
- public void tagGained(TagGainEvent oe)
- {
- System.out.println(oe);
- tag = oe.getValue();
- }
- }
- );
- rfid.addTagLossListener(new TagLossListener()
- {
- public void tagLost(TagLossEvent oe)
- {
- System.out.println(oe);
- tag = "";
- }
- }
- );
- rfid.addOutputChangeListener(new OutputChangeListener()
- {
- public void outputChanged(OutputChangeEvent oe)
- {
- System.out.println(oe);
- }
- }
- );
- rfid.openAny();
- println("waiting for RFID attachment…");
- rfid.waitForAttachment(1000);
- System.out.println("Serial: " + rfid.getSerialNumber());
- System.out.println("Outputs: " + rfid.getOutputCount());
- System.out.println("Outputting events.");
- }
- catch (PhidgetException ex)
- {
- System.out.println(ex);
- }
- }
- void closeReader() {
- try {
- System.out.print("closing…");
- rfid.close();
- rfid = null;
- System.out.println(" ok");
- if (false) {
- System.out.println("wait for finalization…");
- System.gc();
- }
- }
- catch (PhidgetException ex)
- {
- System.out.println(ex);
- }
- }
- void setup()
- {
- size(400, 100);
- // setup Reader
- setupReader();
- // close Reader: Should add a button or some other trigger to call this method
- //closeReader();
- minim = new Minim(this);
- }
- void draw()
- {
- background(200);
- text("Current Tag: "+tag, 50, 50);
- if (tag == songTag && playing == false){
- println("YAY");
- player = minim.loadFile("preview.mp3", 2048);
- player.play();
- playing = true;
- }
- }
1