We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › processing movie
Page Index Toggle Pages: 1
processing movie (Read 715 times)
processing movie
May 2nd, 2008, 1:21am
 
Hello, I am very new to processing and I need some help. I am trying to send information from Arduino that writes it to serial when a button pushed.Processing is reading information from serial and playing one of the movies. Before I push any buttons it plays sound of all the movies I have. Could you tell me what is wrong with my code or if there is another way to do it.
Thank you.




// importing the processing serial class

import processing.serial.*;
import processing.video.*;

Movie  myMovieT, myMovieA;

// definition of window size and framerate
 int xWidth = 768;
 int yHeight = 512;
 int fr = 24;
 int xsp,ysp,xspeed;
 

 
// variables for serial connection, portname and baudrate have to be set
 Serial port;
 String portname = "/dev/tty.usbserial-A9003XAq";
 int baudrate = 9600;
 int value = 0;
 String buf="";
 


void setup(){
 // set size and framerate
 port = new Serial(this, portname, baudrate);
 size(xWidth, yHeight); frameRate(fr);
 background(0);

 myMovieT = new Movie(this, "movie2.mov");
 myMovieA = new Movie(this, "movie3.mov");


myMovieT.stop();
myMovieA.stop();
 }


void serialEvent(int serial){
 
    if(serial == 'G') {  
    myMovieA.stop();
      myMovieT.play();
   image(myMovieT, 0, 0);
    println("Ted");
   } else if(serial == 'I') {  
    myMovieT.stop();
     myMovieA.play();
   image(myMovieA, 0, 0);    
     println("Susan");
       }
         
}

// draw listens to serial port, draw
void draw(){
// listen to serial port and trigger serial event  
 while(port.available() > 0){
  value = port.read();
  serialEvent(value);
  }
 
   
      myMovieA.read();
       myMovieT.read();
     
     


}



Re: processing movie
Reply #1 - May 16th, 2008, 3:04pm
 
Let see. I will make a statical analysis of your source using the reference, as I have no serial device. So I can be wrong...
I was confused by your use of the serialEvent() name, which is also an event callback function from the Serial library. They have a different signature but  I overlooked that.
You read() frames in draw(), but it seems you should to this in movieEvent() callback (called when a frame is really available).
And you should do the image() call in draw() instead. Apparently you do it only when there is a new serial event...
Well, I hope it will push you in the rigth direction.
Page Index Toggle Pages: 1