Using RFID card to play video

I have these two programs working, but I would like to be able to use the card's serial input to play a video, rather than the integer input in the second program. I also don't really understand the integer input I'm getting from reading the RFID card in the second program. Any ideas or insights would be extremely helpful. Thank you in advance.

Program 1:

import processing.serial.*;

Serial myPort;  // The serial port

void setup() {
  // Open the port you are using at the rate you want:
  myPort = new Serial(this, "/dev/tty.usbserial-AD026B9I", 9600);
}

void draw() {
  while (myPort.available() > 0) {
    String inBuffer = myPort.readString();   
    if (inBuffer != null) {
      
      String val = trim(inBuffer); //must trim input because it contains junk
   
      if (val.equals("6F005C5F2A46") == true) {
      println("YES, THIS IS CARD ONE");
      }
      
      if (val.equals("6F005CA5C157") == true) {
      println("WOW!! CARD TWO");
      }
    }
  }
}

Program 2:

import processing.video.*;

Movie myMovie;

import processing.serial.*;

int val ; // To store data from serial port

Serial port; // The serial port object

void setup() {

  size(960, 540);

  // In case you want to see the list of available ports
  // println(Serial.list());

  // Using the right port
  port = new Serial(this, "/dev/tty.usbserial-AD026B9I", 9600);
}

void draw() {
  // The serial data is used to play my movie
  if (val==2) {
    frameRate(30);
    myMovie = new Movie(this, "rain.mov");
    myMovie.play();
  }
}

void movieEvent(Movie m) {
  m.read();
  image(myMovie, 0, 0);
}


// Called whenever there is something available to read
void serialEvent(Serial port) {
  // Data from the Serial port is read in serialEvent() using the read() function and assigned to the global variable: val
  val = port.read();
  // For debugging
  println( "Raw Input:" + val);
  
}

Answers

  • you seem to be on the right track, but I don't fully understand your question. program one reads a string ( I am guessing its null-terminated but I may be wrong), program two reads values byte by byte so you need to keep track of timings to detect end of frame. what values are you getting in your program two? are they not the same? (they should be ASCII values from the string in progr1)

Sign In or Register to comment.