コード例 #1
0
ファイル: Breathing.cs プロジェクト: BUscinski/Firmamentum
    void Update()
    {
        if(breathSensorInitialized)
        {
        //			Debug.Log ("Num Breaths Taken" + numBreathsTaken);
            //Debug.Log (pinValue);
            if(iterator == 0)
            {
                tempMovementValue = 0;
            }
            if(Input.GetKeyDown (KeyCode.Escape)){
                Application.Quit ();
            }
            pinValue = arduino.analogRead(pin);
            if(pinValue >=200f)
            {
                personThere = true;
            }
            //	if(pinValue > previousPinValue)
            if(MovementValue > ((min + max)/2))
            {
                breathingOut++;
                thePointCloud.PushBody ();
            }
            else
            {
                breathingIn++;
                thePointCloud.PullBody ();
            }
        //	Debug.Log ("Pin value: " + pinValue);

            tempMovementValue += pinValue;
            iterator++;
            if(iterator >= 5)
            {
                MovementValue = tempMovementValue/iterator;
        //				Debug.Log ("Updating Movement value to: " + tempMovementValue);
                if(MovementValue > max)
                {
                    max = MovementValue;
                }
                if(MovementValue < min)
                {
                    min = MovementValue;
                }
                iterator = 0;

            }
            if(breathingIn + breathingOut >= 5)
            {
                if(breathingIn > breathingOut)
                {
                    currentBreathStatus = breathStatus.breathingIn;
                }
                if(breathingOut > breathingIn)
                {
                    currentBreathStatus = breathStatus.breathingOut;
                    //breathingOut
                }
                breathingIn = 0;
                breathingOut = 0;
                if(currentBreathStatus != previousBreathStatus && currentBreathStatus == breathStatus.breathingIn)
                {
                    numBreathsTaken++;
                }
                previousBreathStatus = currentBreathStatus;
            }

            previousPinValue = pinValue;
        }
    }
コード例 #2
0
ファイル: Breathing.cs プロジェクト: BUscinski/Firmamentum
    void Update()
    {
        if (breathSensorInitialized)
        {
//			Debug.Log ("Num Breaths Taken" + numBreathsTaken);
            //Debug.Log (pinValue);
            if (iterator == 0)
            {
                tempMovementValue = 0;
            }
            if (Input.GetKeyDown(KeyCode.Escape))
            {
                Application.Quit();
            }
            pinValue = arduino.analogRead(pin);
            if (pinValue >= 200f)
            {
                personThere = true;
            }
            //	if(pinValue > previousPinValue)
            if (MovementValue > ((min + max) / 2))
            {
                breathingOut++;
                thePointCloud.PushBody();
            }
            else
            {
                breathingIn++;
                thePointCloud.PullBody();
            }
            //	Debug.Log ("Pin value: " + pinValue);

            tempMovementValue += pinValue;
            iterator++;
            if (iterator >= 5)
            {
                MovementValue = tempMovementValue / iterator;
//				Debug.Log ("Updating Movement value to: " + tempMovementValue);
                if (MovementValue > max)
                {
                    max = MovementValue;
                }
                if (MovementValue < min)
                {
                    min = MovementValue;
                }
                iterator = 0;
            }
            if (breathingIn + breathingOut >= 5)
            {
                if (breathingIn > breathingOut)
                {
                    currentBreathStatus = breathStatus.breathingIn;
                }
                if (breathingOut > breathingIn)
                {
                    currentBreathStatus = breathStatus.breathingOut;
                    //breathingOut
                }
                breathingIn  = 0;
                breathingOut = 0;
                if (currentBreathStatus != previousBreathStatus && currentBreathStatus == breathStatus.breathingIn)
                {
                    numBreathsTaken++;
                }
                previousBreathStatus = currentBreathStatus;
            }

            previousPinValue = pinValue;
        }
    }