Where did the video go?

Hi there OFpeople,

I’m working on this little piece of script with Arduino and OF,
this is going fine, but I got some problems with the video.

This is what it does:

  1. movieIntro starts playing at the start
  2. once a sensor gets triggered movieA (or movieB) starts playing
  3. once movieA (or movieB) is done, movieIntro starts playing again

Weird thing is, I don’t see movieIntro anywhere.
It’s shown at the start, but not after getting back from movieA (or movieB).
I can see that movieIntro is playing, because movieIntro.getCurrentFrame() is running.

Can you guys spot the problem:

  
  
  
#include "testApp.h"  
  
  
//--------------------------------------------------------------  
void testApp::setup(){  
  
	ofSetVerticalSync(true);  
	ofSetFrameRate(60);  
  
	ofBackground(255,0,130);  
	font.loadFont("franklinGothic.otf", 10);  
  
	ard.connect("/dev/tty.usbserial-A6006f1K", 57600);  
  
	bSetupArduino	= false;  
	introIsTrue		= true;  
	pin0isTrue		= false;  
	pin1isTrue		= false;  
	moviePlaying	= false;  
	  
		  
	//----triggerPoint for pin0  
	light = 985;  
	  
	//----Movies  
	movieIntro.loadMovie("movies/movieTests_Intro.mov");  
	movieA.loadMovie("movies/movieTests_A.mov");  
	movieB.loadMovie("movies/movieTests_B.mov");  
	movieIntro.play();  
}  
  
  
//--------------------------------------------------------------  
void testApp::update(){  
  
	if ( ard.isArduinoReady()){  
  
		// 1st: setup the arduino if haven't already:  
		if (bSetupArduino == false){  
			setupArduino();  
			bSetupArduino = true;	// only do this once  
		}  
		// 2nd do the update of the arduino  
		updateArduino();  
	}  
}  
  
//--------------------------------------------------------------  
void testApp::setupArduino(){  
  
	// this is where you setup all the pins and pin modes, etc  
	for (int i = 0; i < 13; i++){  
		ard.sendDigitalPinMode(i, ARD_OUTPUT);  
	}  
  
	ard.sendDigitalPinMode(13, ARD_OUTPUT);  
	ard.sendAnalogPinReporting(0, ARD_ANALOG);	// AB: report data  
	ard.sendAnalogPinReporting(1, ARD_ANALOG);	// AB: report data  
	ard.sendDigitalPinMode(11, ARD_PWM);		// on diecimelia: 11 pwm?*/	  
}  
  
//--------------------------------------------------------------  
void testApp::updateArduino(){  
	ard.update();  
  
	  
  
	//----Check value of the LDRs  
	if(ard.getAnalog(0) > light && moviePlaying == false){  
		pin0isTrue = true;  
		movieA.play();  
		movieA.setLoopState(OF_LOOP_NONE);  
		movieIntro.setFrame(0);  
		movieIntro.stop();  
		}	  
	  
	if(ard.getAnalog(1) == 1022 && moviePlaying == false){  
		pin1isTrue = true;  
		movieB.play();  
		movieB.setLoopState(OF_LOOP_NONE);  
		movieIntro.setFrame(0);  
		movieIntro.stop();  
		}	  
	  
	  
	//----Check if movie is Done  
	if(movieA.getCurrentFrame() == movieA.getTotalNumFrames()){  
		movieIntro.play();  
		movieA.setFrame(0);  
		movieA.stop();  
		moviePlaying = false;  
	}  
	  
	if(movieB.getCurrentFrame() == movieB.getTotalNumFrames()){  
		movieIntro.play();  
		movieB.setFrame(0);  
		movieB.stop();  
		moviePlaying = false;  
	}  
	  
	  
	//----Check if pin's are true, set others to false	  
	if(pin0isTrue == true){  
		introIsTrue = false;  
		pin1isTrue = false;  
		moviePlaying = true;  
	}  
	  
	if(pin1isTrue == true){  
		introIsTrue = false;  
		pin0isTrue = false;  
		moviePlaying = true;  
	}  
}  
  
//--------------------------------------------------------------  
void testApp::draw(){  
	ofSetColor(255, 255, 255);  
	  
	//----Check if pin's are true, then .draw()  
	  
	if(introIsTrue == true){  
		movieIntro.draw(0,0);  
	}  
	if(pin0isTrue == true){  
		movieA.draw(0,0);  
	}  
	  
	if(pin1isTrue == true){  
		movieB.draw(0,0);  
	}  
	  
	//----intro  
	font.drawString("// movieIntro:", 50, 600);  
	font.drawString("getCurrentFrame: " + ofToString(movieIntro.getCurrentFrame()), 50, 620);  
	font.drawString("getTotalNumFrames: " + ofToString(movieIntro.getTotalNumFrames()), 50, 640);  
	  
	//----movieA  
	font.drawString("// movieA:", 250, 600);  
	font.drawString("getCurrentFrame: " + ofToString(movieA.getCurrentFrame()), 250, 620);  
	font.drawString("getTotalNumFrames: " + ofToString(movieA.getTotalNumFrames()), 250, 640);  
	  
	//----movieB  
	font.drawString("// movieB:", 450, 600);  
	font.drawString("getCurrentFrame: " + ofToString(movieB.getCurrentFrame()), 450, 620);  
	font.drawString("getTotalNumFrames: " + ofToString(movieB.getTotalNumFrames()), 450, 640);  
	  
	  
	//----Arduino  
	if (!ard.isArduinoReady()){  
		font.drawString("// Arduino:", 650, 600);  
		font.drawString("arduino not ready\n", 650, 620);  
	} else {  
		font.drawString("// Pins:", 650, 600);  
		font.drawString("analog pin 0: " + ofToString(ard.getAnalog(0)), 650, 620);  
		font.drawString("analog pin 1: " + ofToString(ard.getAnalog(1)), 650, 640);  
	}  
	  
	//----Is movie done:  
	font.drawString("// Is the movie done:",850,600);  
	font.drawString("movieIntro:",850,620);  
	font.drawString("movieA:",850,640);  
	font.drawString("movieB:",850,660);  
	  
	if(movieIntro.getIsMovieDone()){  
        font.drawString("Yes",970,620);  
    } else {  
		   font.drawString("No",970,620);  
	}  
  
	  
	if(movieA.getIsMovieDone()){  
        font.drawString("Yes",970,640);  
    } else {  
		font.drawString("No",970,640);  
	}  
	  
	if(movieB.getIsMovieDone()){  
        font.drawString("Yes",970,660);  
    }else {  
		font.drawString("No",970,660);  
	}  
}  
  
//--------------------------------------------------------------  
void testApp::keyPressed  (int key){  
	  
}  
  
  

I’ve posted the code (+vids) in a .zip:

http://www.petervdwerve.nl/download/002-…-erKris.zip

Does someone see what I’m doing wrong?

Hello Peter!

I guess it has to do with your pin logic. As far as I can see your introIsTrue boolean never gets true again. Also pin0isTrue and pin1isTrue only get reset, if you press a button, not if one of the movies stopped. So when debugging your draw()-function, the last movie played gets still drawn, as e.g. pin0isTrue is always true.

Regards,
Gestalt

Hi Gestalt,

Thanks for replying!

I’m going check if it works, once I get home.
I’ll let you know if it fixed the problem.

Greets,
Peter.

Hi Gestalt,

Thanks!
It’s works!

I got so stuck, since I’m not the best programmer,
and I didn’t get anymore errors and still it didn’t do what I wanted…

But thanks!

Greets,
Peter.

Hello Peter!

Nice that I could help. If I can give you a hint: Learn how to use the debugger. Xcode makes this really easy and so you can go step by step through your prgramm and see, what it really does!

regards,
Gestalt