From ec078a99e2924c1709242f981651409f7ae9e940 Mon Sep 17 00:00:00 2001 From: Tim Redfern Date: Fri, 23 Mar 2012 01:41:25 +0000 Subject: working with arduino --- src/testApp.cpp | 83 ++++++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 68 insertions(+), 15 deletions(-) (limited to 'src/testApp.cpp') diff --git a/src/testApp.cpp b/src/testApp.cpp index 081c3e6..dff1f18 100644 --- a/src/testApp.cpp +++ b/src/testApp.cpp @@ -1,6 +1,7 @@ #include "testApp.h" //-------------------------------------------------------------- testApp::~testApp(){ + ard.disconnect(); // closes the serial port connection saveSettings("settings.xml"); } //-------------------------------------------------------------- @@ -27,19 +28,25 @@ void testApp::setup(){ //model.setRotation(0, 90, 0, 1, 0); model.setPosition(model_x, model_y, model_z); + calibrator_label.loadMovie("calibrator_label.mov"); + calibrator_label.setLoopState(OF_LOOP_NORMAL); + calibrator_label.play(); //ofDisableArbTex(); mode=DISPLAY; + transTime=0; + transition=false; - - whichClip=0; + whichClip=1; //0 is black + switchClip=1; //0 is black texture.loadMovie(clips[whichClip]); texture.setLoopState(OF_LOOP_NORMAL); texture.play(); light=true; + mixAmount=1.0; camWidth = 320; // try to grab at this size. camHeight = 240; @@ -65,6 +72,10 @@ void testApp::setup(){ //-------------------------------------------------------------- void testApp::update(){ texture.idleMovie(); + calibrator_label.idleMovie(); + + //mixAmount=sin(ofGetElapsedTimef())+1.0; + doTransition(); if (mode==GRAB) { vidGrabber.grabFrame(); @@ -81,7 +92,6 @@ void testApp::update(){ videoTexture.loadData(videoInverted, camWidth,camHeight, GL_RGB); } } - updateArduino(); } @@ -109,16 +119,28 @@ void testApp::updateArduino(){ // do not send anything until the arduino has been set up if (bSetupArduino) { + + if (bSwitchArduino!=ard.getDigital(7)) { bSwitchArduino=ard.getDigital(7); printf("pin 7 %i\n",bSwitchArduino); + if (!bSwitchArduino) { + whichClip=max(1,switchClip); + transTime=ofGetElapsedTimef()+0.5; + } + else { + switchClip=whichClip; + whichClip=0; + transTime=ofGetElapsedTimef()+0.1; + } + + transition=true; } } } //-------------------------------------------------------------- void testApp::draw(){ - if (mode!=CALIBRATE&&bSetupArduino&!bSwitchArduino) return; for (int i=0;i': - whichClip=(whichClip+1)%numClips; - texture.stop(); - texture.loadMovie(clips[whichClip]); - texture.play(); + whichClip=max(1,(whichClip+1)%numClips); + transTime=ofGetElapsedTimef()+1.0; + transition=true; break; case '/': light=!light; printf(light?"LIGHT ON\n":"LIGHT OFF\n"); break; + case '`': + ard.disconnect(); // closes the serial port connection + printf("arduino disconnected\n"); + break; } } +void testApp::doTransition(){ + if (transition) { + if (ofGetElapsedTimef()>transTime) { + texture.stop(); + texture.loadMovie(clips[whichClip]); + texture.play(); + transition=false; + } + + } + mixAmount=min(abs(ofGetElapsedTimef()-transTime),1.0f); + if (whichClip==0&&!transition) mixAmount=0; +} //-------------------------------------------------------------- void testApp::keyReleased(int key){ if (activeView<0) for (int i=0;i