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.
Page Index Toggle Pages: 1
video playback/switch triggering (Read 588 times)
video playback/switch triggering
Dec 18th, 2009, 3:49pm
 
Hi
I'm having serious problems and I'm not entirely sure what to do or how to see where the problems is
I have this code that I'm working on w/ processing and arduino

here's the processing:

import processing.video.*;
Movie myMovie;
Movie myMovie2;
float dur = 0;



import processing.serial.*;

Serial myPort;
int val;      
int num = 0;
int pla = 0;
float overalltime = 0;
float range = 0;

int whichPlaying = 0;

void setup() {
 size(1024, 768, P2D);
 
 
 String portName = Serial.list()[0];
 myPort = new Serial(this, portName, 9600);
}

void draw() {
 rect(0, 0, 1024, 768);
 
 if (myPort.available() > 0) {  
   val = myPort.read();      
 }
 
 if(val == 1) {
   if (whichPlaying != 1) {
     myMovie = new Movie(this, "test4.mov");
     myMovie.loop();
     whichPlaying = 1;
   }
 } else {
   if (whichPlaying != 2) {
     myMovie = new Movie(this, "test2.mov");
     myMovie.loop();
     whichPlaying = 2;
   }
 }
image(myMovie, 10, 10);
 }


 if(val == 3) {
   if (whichPlaying != 3) {
     myMovie = new Movie(this, "test3.mov");
     myMovie.loop();
     whichPlaying = 3;
   }
 } else {
   if (whichPlaying != 4) {
     myMovie = new Movie(this, "test.mov");
     myMovie.loop();
     whichPlaying = 4;
   }
   image(myMovie, 0, 0);
 }
 
 }
  if(val == 5) {
   if (whichPlaying != 5) {
     myMovie = new Movie(this, "test5.mov");
     myMovie.loop();
     whichPlaying = 5;
   }
   image(myMovie, 0, 0);
  }
 
 } else {
   if (whichPlaying != 6) {
     myMovie = new Movie(this, "test6.mov");
     myMovie.loop();
     whichPlaying = 6;
   }
 }
 image(myMovie, 0, 0);
}




void mousePressed() {
 val = 1;
}

void movieEvent(Movie m) {
 m.read();
}

and the arduino code:
const int buttonPin = 2;    
const int ledPin =  13;
const int tiltPin1 = 3;
const int tiltPin2 = 4;
const int tiltPin3 = 5;
const int tiltPin4 = 6;
const int tiltPin5 = 7;


int buttonState = 0;
int tiltState1 = 0;
int tiltState2 = 0;
int tiltState3 = 0;
int tiltState4 = 0;
int tiltState5 = 0;


void setup() {
Serial.flush();
Serial.begin(9600);
 pinMode(buttonPin, INPUT);  
 pinMode(tiltPin1, INPUT);
 pinMode(tiltPin2, INPUT);
 pinMode(tiltPin3, INPUT);
 pinMode(tiltPin4, INPUT);
 pinMode(tiltPin5, INPUT);
}

void loop(){
 
 buttonState = digitalRead(buttonPin);

 if (buttonState == HIGH) {    
   Serial.print(1, BYTE);
   digitalWrite(ledPin, HIGH);  
 }
 
 
   tiltState1 = digitalRead(tiltPin1);

 if (tiltState1 == HIGH) {    
   Serial.print(2, BYTE);
   digitalWrite(ledPin, HIGH);  
 }
 
  tiltState2 = digitalRead(tiltPin2);

 if (tiltState2 == HIGH) {    
   Serial.print(3, BYTE);
   digitalWrite(ledPin, HIGH);  
 }
 
  tiltState3 = digitalRead(tiltPin3);

 if (tiltState3 == HIGH) {    
   Serial.print(4, BYTE);
   digitalWrite(ledPin, HIGH);  
   
 }
 
  tiltState4 = digitalRead(tiltPin4);

 if (tiltState4 == HIGH) {    
   Serial.print(5, BYTE);
   digitalWrite(ledPin, HIGH);  
   
 }
 
  tiltState5 = digitalRead(tiltPin5);

 if (tiltState5 == HIGH) {    
   Serial.print(6, BYTE);
   digitalWrite(ledPin, HIGH);  
   
 }
 
 
 
 delay(100);
}


I'm trying to work so that three tilt switches set off video programs. One of the switches is responding and the other two are not showing an response (I think its in the code, I've double checked the connections on the breadboard), and the video isn't playing. I'm trying to get each video to play at seperate times when the switch is activated, however, they're all playing at once and I need them to play through and stop once it has been activated, not restart or loop when other switches are triggered.
I hope I've explained this well,
thanks for any help
Page Index Toggle Pages: 1