Exemple #1
0
//--------------------------------------------------------------
void ofApp::update(){
	if (arduinoAttached){
		updateArduino();
		if (!bSetupArduino){
			if (ard.isArduinoReady()){
				ofLogNotice("Connecting") << "setting up arduino";
				setupArduino(0);
			}
		}
	}
}
void ofApp::update()
{
	// ARDUINO MESSAGES
	updateArduino();

	// OSC MESSAGES
	sendMessage();
	getRenderFromServer();

	// PROCESSING BYTES
	players.at(1)->processArduino(receivedBytes);
}
Exemple #3
0
//--------------------------------------------------------------
void testApp::update() {
    /////////////
	// ofxBeatTracking update
    //////////
    // To update the object BeatDetect
    // The calculation is performed of whether the beat has been detected at this time
    // The result of the calculation is obtained from the function, such as () bd.isBeat
    bd.updateFFT();

    /////////////
    // Arduino Firmata communication update
    //////////
	updateArduino();
}
Exemple #4
0
//--------------------------------------------------------------
void ofApp::update()
{
    
    dir.x = ofRandomf() * 1.57;
    pos.x = (width / 2.0) + (ofRandomf() * 0.5);
    
    
    if(isDrawS && !isPaused)
        fluid.addTemporalForce(pos, dir, ofFloatColor(0.12, 0.09, 0.09), rad, temp, den);
    
    if(isPaused)
        pCount += ofGetFrameRate() / 60;
    if(pCount >= pTime)
    {
        pCount = 0;
        isPaused = false;
    }
    
    if(!isStatA)
        ofSetWindowShape(width, height);
    else
        ofSetWindowShape(width + 85.0, height);
    
    //  Update
    //
    fluid.update();
    
    ofSetWindowTitle(ofToString(ofGetFrameRate()));
    
    updateArduino();
    
    if(!isPaused)
    {
        
        irsVal = (float)ard.getAnalog(5);
    }
    
    
    if(irsVal < 590.0)
    {
        isPaused = true;
    }
    else
    {
        isPaused = false;
    }
    

}
Exemple #5
0
//--------------------------------------------------------------
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::update(){

	updateArduino();
    ofSoundUpdate();
    
    int currentTime = ofGetElapsedTimef();
    
    if (currentTime > (timeElasped+cycleTime)) {
        // slow down the random number generator to prevent audio glitching
        randomGurgle = ofRandom(0,NUM_GURGLE);
        randomSound = ofRandom(0,NUM_BREATHE);
        timeElasped = currentTime;
        cout << "Random Sound# " << randomSound << " Random Gurgle #" << randomGurgle << endl;
    }
    // slow down the update of the random gurgle
    
    inhaleExhaleSound[randomSound].setSpeed(breathespeed);
    inhaleExhaleSound[randomSound].setMultiPlay(false);
    inhaleExhaleSound[randomSound].play();
    
}
Exemple #7
0
//--------------------------------------------------------------
void testApp::update(){
    
	int threshold = 20;// you can change the value here
	ps3eye.update();

    updateArduino();

	if (ps3eye.isFrameNew()){
		
		videoColorCvImage.setFromPixels(ps3eye.getPixels(), camWidth, camHeight);
		videoGrayscaleCvImage = videoColorCvImage;
		
		if (ofGetElapsedTimef() < 1.5){
			videoBgImage = videoGrayscaleCvImage;
		}
		
		videoDiffImage.absDiff(videoGrayscaleCvImage, videoBgImage);
		videoDiffImage.threshold(threshold);
	}
	
}
Exemple #8
0
void testApp::update() {
   // Arduinoを更新
   updateArduino();
   float ardIn = (float)ard.getAnalog(0) / 2048.0f;
   
	float t = ofGetElapsedTimef();
	float div = 100.0f;
	for (int i=0; i<NUM_PARTICLES; i++) {
		ofVec3f vec(ofSignedNoise(t, myVerts[i].y/div, myVerts[i].z/div),
                  ofSignedNoise(myVerts[i].x/div, t, myVerts[i].z/div),
                  ofSignedNoise(myVerts[i].x/div, myVerts[i].y/div, t));
		vec *= ardIn;
		myVels[i] += vec;
		myVerts[i] += myVels[i];
		myVels[i]  *= 0.9f;	
	}
   // move the camera around
	float mx = (float)mouseX/(float)ofGetWidth();
	float my = (float)mouseY/(float)ofGetHeight();
	ofVec3f des(mx * 360.0, my * 360.0, 0);
	cameraRotation += (des-cameraRotation) * 0.03;
}
//--------------------------------------------------------------
void testApp::update(){
	updateArduino();	
	ofBackground(0,0,0);

    bool bNewFrame = false;

	#ifdef _USE_LIVE_VIDEO
       vidGrabber.grabFrame();
	   bNewFrame = vidGrabber.isFrameNew();
    #else
        vidPlayer.idleMovie();
        bNewFrame = vidPlayer.isFrameNew();
	#endif

	if (bNewFrame){

		#ifdef _USE_LIVE_VIDEO
            colorImg.setFromPixels(vidGrabber.getPixels(), 640,480);
	    #else
            colorImg.setFromPixels(vidPlayer.getPixels(), 640,480);
        #endif

        grayImage = colorImg;
		if (bLearnBakground == true){
			grayBg = grayImage;		// the = sign copys the pixels from grayImage into grayBg (operator overloading)
			bLearnBakground = false;
		}

		// take the abs value of the difference between background and incoming and then threshold:
		grayDiff.absDiff(grayBg, grayImage);
		grayDiff.threshold(threshold);

		// find contours which are between the size of 20 pixels and 1/3 the w*h pixels.
		// also, find holes is set to true so we will get interior contours as well....
		contourFinder.findContours(grayDiff, 20, (640*480)/3, 1, false);	// find holes
	}

}
Exemple #10
0
//--------------------------------------------------------------
void ofApp::update(){
    updateArduino();
    
    //SEND TO WEKINATOR
    ofxOscMessage toWeki;
    toWeki.setAddress("/wek/inputs");
    toWeki.addFloatArg(analogValue[0]);
    toWeki.addFloatArg(analogValue[1]);
    
    sender.sendMessage(toWeki);
    isMessageSent = true;
    
    //RECEIVE FROM WEKINATOR
        while(receiver.hasWaitingMessages()){
            // get the next message
            ofxOscMessage toWeki;
            receiver.getNextMessage(&toWeki);
    
            if(toWeki.getAddress() == "/wek/outputs"){
                message = toWeki.getArgAsFloat(0);
                rad = message;
            }
}
}
//--------------------------------------------------------------
void ofApp::update(){
    
    grabber.update();
    
    if (grabber.isFrameNew()){
        
        colorImage.setFromPixels(grabber.getPixelsRef());
        currFrame = colorImage;
        currFrame.flagImageChanged();
        
        diffImage.absDiff( currFrame, prevFrame );
        diffImage.threshold(mouseX/10);
        
        int nWhitePixels = diffImage.countNonZeroInRegion(0, 0, 320, 240);
        cout << nWhitePixels << endl;
        
        pixels_LED = nWhitePixels;
        
        prevFrame = currFrame;
    }
    
    updateArduino();

}
Exemple #12
0
//--------------------------------------------------------------
void gamuzaMain::update(){

    char temp_message[512];

	//////////////////////////////////////////////
	// INIT PROGRAM | splash image control
	if(ofGetElapsedTimeMillis() > splashWait){
		splashFinish = true;
		if(flagSystemLoaded){
			flagSystemLoaded = false;
            sprintf(temp_message,"OpenGL version: %s", glGetString (GL_VERSION));
            sendPrivateMessage(GAMUZA_CONSOLE_LOG, temp_message);
            sendPrivateMessage(GAMUZA_CONSOLE_LOG, " ");
            if(GL_ARB_shader_objects){
                sprintf(temp_message,"GL_ARB_shader SUPPORTED by your Graphic Card: %s", glGetString (GL_RENDERER));
                sendPrivateMessage(GAMUZA_CONSOLE_LOG, temp_message);
                sendPrivateMessage(GAMUZA_CONSOLE_LOG, " ");
            }else{
                sprintf(temp_message,"GL_ARB_shader NOT SUPPORTED by your Graphic Card: %s", glGetString (GL_RENDERER));
                sendPrivateMessage(GAMUZA_CONSOLE_LOG, temp_message);
                sendPrivateMessage(GAMUZA_CONSOLE_LOG, "switching to SHADER OFF MODE");
                sendPrivateMessage(GAMUZA_CONSOLE_LOG, " ");
            }

			if(audioActivated){
				soundStream.start();
                sendPrivateMessage(GAMUZA_CONSOLE_LOG, "soundStream STARTED");
                sendPrivateMessage(GAMUZA_CONSOLE_LOG, " ");
				for(unsigned int i = 0; i < audioInputChannels; i++){
					inputAudioCH[i].computeChannel = true;
				}
				computeAudioInput	= true;
				computeAudioOutput	= true;

			}
            if(arduinoActivated){
                sendPrivateMessage(GAMUZA_CONSOLE_LOG, "ARDUINO connection established");
                sendPrivateMessage(GAMUZA_CONSOLE_LOG, " ");
            }
		}
		//////////////////////////////////////////////
		// Main settings control
		ofSetVerticalSync(useVSync);
		//////////////////////////////////////////////

		//////////////////////////////////////////////
		// GUI update
		updateGui();
		gui.update();
		//////////////////////////////////////////////

        //////////////////////////////////////////////
		// FBO Output Texture update
        updateFBO();
        //////////////////////////////////////////////

		//////////////////////////////////////////////
		// OPENNI
		if(openniActivated && sensorKinect.useKinect && sensorKinect.isOniConnected){
			sensorKinect.updateDevice();
		}
		//////////////////////////////////////////////

		//////////////////////////////////////////////
		// WEBCAM input devices update
		if(trackingActivated){
			for(unsigned int i=0;i<numCamInputs;i++){
				if(inputCam[i].captureVideo){
					inputCam[i].update();
				}
			}
		}
		//////////////////////////////////////////////

		//////////////////////////////////////////////
		// ARDUINO update
		if(arduinoActivated && useArduino){
			updateArduino();
		}
		//////////////////////////////////////////////

	}
	//////////////////////////////////////////////

    //////////////////////////////////////////////
    // OSC update
    updateOSC();
    // OSC messages receiving
    receiveOSC();
    //////////////////////////////////////////////

	//////////////////////////////////////////////
	// SYSTEM
	gamuzaRealFPS = ofGetFrameRate();
    gaFrameCounter++;
	//////////////////////////////////////////////

}
Exemple #13
0
//--------------------------------------------------------------
void ofApp::update(){
  
    //--ARD
    updateArduino();

    //--osc
    oscReceive();
    
    //--audio background
    ofSoundUpdate();
    
//---kasia---updating timer for image
     timer = ofGetElapsedTimeMillis();
    
   // instructions.draw(350,120);


    //--daisy
    if (!bLovesMe_Selected) {//comment this out and close bracket at end of if-statement
        
        for (int i=0; i<myFlws.size(); i++) {
            myFlws[i].resetForce();
        }
        
        for (int i=0; i<myFlws.size(); i++) {
            myFlws[i].addRepulsionForce(myFlws[i].pos.x, 0, 30, 1);
        }
        
        for (int i=0; i<myFlws.size(); i++) {
            if (bClean) {
                myFlws[i].bClean = true;
                myFlws[i].addAttractionForce(-100, ofGetHeight()/2, 3000, 0.5);
                
            
            }else{
                myFlws[i].bounceOffWalls();
            }
            myFlws[i].update();
            
            //clean
            ofRectangle window;
            window.set(-100, -100, ofGetWidth()+100, ofGetHeight()+100);
            
            if (!window.inside(myFlws[i].pos)&& bClean) {
                myFlws[i].bNotDrawDaisy = true;
            }

            for (int j=0; j<myFlws[i].myPetals.size(); j++) {
                if (!window.inside(myFlws[i].myPetals[j].pos)&& bClean) {
                    myFlws[i].myPetals.erase(myFlws[i].myPetals.begin()+j);
           
                }
            }
            
            if (myFlws[i].myPetals.size() == 0) {
                myFlws.erase(myFlws.begin()+i);
            }
        }
        
        for (int i=0; i<myFlwSmall.size(); i++) {
            myFlwSmall[i].resetForce();
            if (bClean) {
                myFlwSmall[i].addAttractionForce(-100, ofGetHeight()/2, 3000, 0.5);
            }else{
                myFlwSmall[i].bounceOffWalls();
            }
            myFlwSmall[i].addDampingForce();
            myFlwSmall[i].update();
            
            //clean
            ofRectangle window;
            window.set(-100, -100, ofGetWidth()+100, ofGetHeight()+100);
            if (!window.inside(myFlwSmall[i].pos) && bClean) {
                myFlwSmall.erase(myFlwSmall.begin()+i);
                          }
        }
    }
    
    
    // bee touch loves me
    for (int i=0; i<myFlws.size(); i++) {
        for (int j=0; j<myFlws[i].myPetals.size(); j++) {
            if(myFlws[i].myPetals[j].bSelected && myFlws[i].myPetals[j].bIsLovesMe && !bClean){
                bLovesMe_Selected =true;
                ard.sendDigital(13,ARD_HIGH);
                break;
            }
            
        }
    }
    
    //scale change
    for (int i=0; i<myFlws.size(); i++) {
        for(int j=0; j< myFlws[i].myPetals.size(); j++){
            myFlws[i].myPetals[j].scaleUpdate();
        }
    }
    
    
    
    if (bLovesMe_Selected) {
        for (int i=0; i<myFlws.size(); i++) {
            for (int j=0; j<myFlws[i].myPetals.size(); j++) {
                if(myFlws[i].myPetals[j].bSelected){
                    if (myFlws[i].myPetals[j].scalePct == 1) {
                        bClean =true;
                        bLovesMe_Selected = false;
                        (ard.sendDigital(13,ARD_LOW));
                        
                        
//                        ofEnableAlphaBlending();
//                        for (int i=0; i<end.size(); i++)
//                        {
//                            end[i].draw();
//                        }
                        break;
                        
                        
                       
                    }
                    break;
                }
            }
        }
    }
    
    
    //-----timer for clean----
    if (ofGetElapsedTimeMillis() - cleanerTimer> cleanTime && !bClean) {
        bClean = true;
    }
    
    if (myFlws.size() == 0 && myFlwSmall.size() == 0) {
        bClean =false;
        cleanerTimer = ofGetElapsedTimeMillis();
    }
    
    if (ofGetElapsedTimeMillis() -  buttonTimer >= 3000) {
        bButton = true;
        bEmit = false;
        buttonTimer = ofGetElapsedTimeMillis();
    }
    
    
    //---kasia--timer for image
   

    /*if(bClean && timer-preTimer > 10000){
        end.draw(190,120);
    }*/
    
//  sound----------------
    updateSound();
    
}
Exemple #14
0
//--------------------------------------------------------------
void ofApp::update()
{
    updateArduino();

}
Exemple #15
0
//--------------------------------------------------------------
void testApp::update(){

	updateArduino();

}
Exemple #16
0
//--------------------------------------------------------------
void ofApp::update(){

			if(myArduino.isArduinoReady()){
		//when bsetupArduino is false it will run the setupArdiono to define the in and output of the arduiono
		if(bSetupArduino==false){
			setupArduino();
	//		we started running arduino, so no need to start setup again. 
			bSetupArduino=true;
		}
		//2nd run the update
		updateArduino();
	}
			
	if(GameStart==true){
	check= ofGetElapsedTimeMillis();
		if(check>=counter){
			distanceRight=myArduino.getAnalog(0); //analog pin A0
			distanceLeft=myArduino.getAnalog(1); //analog pin A1
			// change 0-1023 to centimeters
			Rightvolt=ofMap(distanceRight, 0, 1023, 0, 5000); //5 volts
			Leftvolt=ofMap(distanceLeft, 0, 1023, 0, 5000); 
			Right=(21.61/(Rightvolt-0.1696))*1000;
			Left=(21.61/(Leftvolt-0.1696))*1000;
			counter=check+500; 
		}

		//map the variables of the ir sensor to the width and hight of the screen.
		x=ofMap(Right,8,30,ofGetWidth(),0);
		y=ofMap(Left,8,30,ofGetHeight(),0);

		// if the value of the sensors is higher then 50 set player in center of the screen.
	if(Right>30){
		x=ofGetWidth()/2;
	}
	if(Left>30){
		y=ofGetHeight()/2;
	}

	//make target smaller;
	for(int i=0; i<points; i++){
		rectSize= 40 - i*2;
	}
	

	//player code
	for(int i=0; i<1+points; i++){
	player[i].update();
	player[i].checkEdges();
	}

	if(rectSize<1){
		GameStart=false;
		time=check;
	}

	
	}else{
		
		rectSize=40;
	
	}
	cout<<check/1000<< endl;


}
//--------------------------------------------------------------
void testApp::update() {

    myVideo.update();

    float amp = (AAleft.amplitude + AAright.amplitude) / 2.0;
    int numHairs = ofMap(amp, .01, .2, 0, 10, true);
    currentRadius = ofMap(amp, .01, .2, 6, 28, true);

    for(int i=0; i<numHairs; i++)
    {
        Hair h;
        h.setup();
        hairs.push_back( h );
        cout << "adding hair" << endl;
    }

    for(int i=0; i<hairs.size(); i++)
    {
        hairs[i].update(theHair, lines, currentRadius);

        if(hairs[i].position.y > ofGetHeight())
        {
            hairs.erase( hairs.begin() + i );
        }
    }

    updateArduino();

    for(int i = 0; i < NUM; i++) {

        //if(mouse_pressed){
        if(ardButtonPressed) {

            speed_x[i] = (ofGetWidth()/2- loc_x[i]) / 8.0;
            speed_y[i] = (ofGetHeight()/2 - loc_y[i]) / 8.0;
        }

        speed_x[i] = speed_x[i] * friction;
        speed_y[i] = speed_y[i] * friction;
        speed_y[i] = speed_y[i] + gravity;

        loc_x[i] = loc_x[i] + speed_x[i];
        loc_y[i] = loc_y[i] + speed_y[i];

        if(loc_x[i] < 0) {
            loc_x[i] = 0;
            speed_x[i] = speed_x[i] * -1.0;
        }
        if(loc_x[i] > ofGetWidth()) {
            loc_x[i] = ofGetWidth();
            speed_x[i] = speed_x[i] * -1.0;
        }
        if(loc_y[i] < 0) {
            loc_y[i] = 0;
            speed_y[i] = speed_y[i] * -1.0;
        }
        if(loc_y[i] > ofGetHeight()) {
            loc_y[i] = ofGetHeight();
            speed_y[i] = speed_y[i] * -1.0;
        }
    }

    int buttonState = ard.getDigital(2);
    if(buttonState == true) {
        //mouse_pressed    = true;
        ardButtonPressed   = true;

    } else     if(buttonState == false) {
        //mouse_pressed = false;
        ardButtonPressed = false;
    }




}
Exemple #18
0
//--------------------------------------------------------------
void shelfApp::update(){

	updateArduino();
}
//--------------------------------------------------------------
void ofApp::update(){

    //pulls info from Arduino each frame
    updateArduino();
    
}
Exemple #20
0
//--------------------------------------------------------------
void gamuzaMain::update(){

	//////////////////////////////////////////////
	// INIT PROGRAM | splash image control
	if(ofGetElapsedTimeMillis() > splashWait){
		splashFinish = true;
		if(flagSystemLoaded){
			flagSystemLoaded = false;
			if(audioActivated){
				soundStream.start();
				printf("\nsoundStream STARTED\n\n");
				logger.log(99, " soundStream STARTED");
				for(unsigned int i = 0; i < audioInputChannels; i++){
					inputAudioCH[i].computeChannel = true;
				}
				computeAudioInput	= true;
				computeAudioOutput	= true;

			}
		}
		//////////////////////////////////////////////
		// Main settings control
		ofSetVerticalSync(useVSync);
		//////////////////////////////////////////////

		//////////////////////////////////////////////
		// GUI update
		updateGui();
		gui.update();
		//////////////////////////////////////////////

		//////////////////////////////////////////////
		// OPENNI
		if(openniActivated && sensorKinect.useKinect){
			sensorKinect.updateDevice();
		}
		//////////////////////////////////////////////

		//////////////////////////////////////////////
		// WEBCAM input devices update
		if(trackingActivated){
			for(unsigned int i=0;i<numCamInputs;i++){
				if(inputCam[i].captureVideo){
					inputCam[i].update();
				}
			}
		}
		//////////////////////////////////////////////

		//////////////////////////////////////////////
		// ARDUINO update
		if(arduinoActivated && useArduino){
			updateArduino();
		}
		//////////////////////////////////////////////

		//////////////////////////////////////////////
		// OSC update
		if(oscActivated && useOsc){
			updateOSC();
		}
		//////////////////////////////////////////////
	}
	//////////////////////////////////////////////

	//////////////////////////////////////////////
	// Various reference var
	gamuzaRealFPS = ofGetFrameRate();
	//////////////////////////////////////////////

}
Exemple #21
0
//--------------------------------------------------------------
void ofApp::update(){
	//all math stuff
		
	//first step
	//if my arduino is ready ---> its a must to make openframworks to run with the arduino
	if(myArduino.isArduinoReady()){
		//when bsetupArduino is false it will run the setupArdiono to define the in and output of the arduiono
		if(bSetupArduino==false){
			setupArduino();
	//		we started running arduino, so no need to start setup again. 
			bSetupArduino=true;
		}
		//2nd run the update
		updateArduino();
	}
		
	if(hasLostGame==false){
		//playerspeed


		//player one controls
		if(players[1].up==true){
			players[1].YposPlayer --;
		}
		if(players[1].down==true){
			players[1].YposPlayer++;
		}
		if(players[1].left==true){
			players[1].XposPlayer --;
		}
		if(players[1].right==true){
			players[1].XposPlayer++;
		}
		//player 2 controls
		if(players[2].up==true){
			players[2].YposPlayer --;
		}
		if(players[2].down==true){
			players[2].YposPlayer++;
		}
		if(players[2].left==true){
			players[2].XposPlayer --;
		}
		if(players[2].right==true){
			players[2].XposPlayer++;
		}

	  pullToPlayer();
	 // //player score counter. player 1
		if(ofDist(players[1].XposPlayer,players[1].YposPlayer,players[2].XposWeapon,players[2].YposWeapon) < players[1].playerRadius+WeaponRadius){
			players[2].playerHit=true;
			Hitvalue2++;
			if(players[2].playerHit==true && Hitvalue2==1){
			players[2].playerScore++;
			Hit.play();
			
			}
		}else{
			players[2].playerHit=false;
			Hitvalue2=0;
		}
		
		
		//player score 2
		if(ofDist(players[2].XposPlayer,players[2].YposPlayer,players[1].XposWeapon,players[1].YposWeapon) < players[1].playerRadius+WeaponRadius){
			players[1].playerHit=true;
			Hitvalue1++;  //counts up when true
			if(players[1].playerHit==true && Hitvalue1==1){ //when it is 1 score will go +1
			players[1].playerScore++;
			Hit.play();
			
			}
			//when false the counter will reset so when it hits again you add 1 to the score again.
		}else{
			players[1].playerHit=false;
			Hitvalue1=0;
		}
		if(players[1].playerScore>=5 || players[2].playerScore==5){
			hasLostGame=true;
		}

	}

}