Back to Parent

// Serial Port Communication library
import processing.serial.*;
import processing.sound.*;

SoundFile no;
SoundFile ok;

//New instance of Serial Port
Serial port;

String id = "";
String buff = "";
// Setup a new instance of image
PImage img; 
 
 
void setup() {
  background(0,0,0); 
  size(640, 540);
  // Set the Processing Sketch always on Top
  surface.setAlwaysOnTop(true);
  // List of Serial Port / COM Port
  //printArray(Serial.list());
  // Choose the correct Serial Port / COM Port
  // Baud Rate must match the Arduino Sketch 
  // format: new Serial(this, Serial Port / COM Port, Baud Rate); 
  port = new Serial(this, "/dev/cu.usbmodem14101", 9600);
  no = new SoundFile(this, "data/ohno.mp3");
  ok = new SoundFile(this, "data/ok.mp3");
}
void draw(){
  // Check if the port send anything
  if(port.available() > 0) {
    // Read the port 
    serialEvent(port.read());  
  }
}
 
void serialEvent(int serial) {
  // Get all the information in buffer string until new line
  if(serial != '\n') { 
    buff += char(serial);
  } 
  /* Trim the buff to get the ID Hexadecimal
     This depends on how you send the data */
  else {   
   id = trim(buff.substring(0));
   // Load Oh no image
   if ((id.equals("48281A4A6E81")) || (id.equals("44681A4A6E81")) || (id.equals("45B81A4A6E81"))) {
     img = loadImage("ohno.jpg");
     image(img, 0, 0);
     no.stop();
     no.play();
     
   // Load yeah okay image
   } else if ((id.equals("46E81A4A6E81")) || (id.equals("44781A4A6E81")) || (id.equals("47081A4A6E81"))){
     background(0,0,0);
     no.stop();
img = loadImage("sure.jpg");
     image(img, 0, 0);
     ok.play();
     
   // If anything other RFID tag reset  
   } else {
     background(0,0,0); 
   }
   // Reset Buffer String
   buff = "";
  }
}
Click to Expand

Content Rating

Is this a good/useful/informative piece of content to include in the project? Have your say!

0