Example #1
0
    // Use this for initialization
    void Start()
    {
        curValues = new int[16];  // numbers is a 16-element array

        sp = UnitySerialPort.Instance;
        sp.OpenSerialPort();
    }
Example #2
0
    // Update is called once per frame
    void Update()
    {
        //catch if SP is closed, make sure it's open
        if (!sp.SerialPort.IsOpen)
        {
            sp.OpenSerialPort();
        }

        str       = sp.RawData;
        curValues = splitString(str);

        //init values with specific array member
        int o = oldValues[8];
        int c = curValues[8];

        Debug.Log(c);

        if (o < c)
        {
            myDir = IntensityDirection.Increase;
        }
        if (o == c)
        {
            myDir = IntensityDirection.Same;
        }
        if (o > c)
        {
            myDir = IntensityDirection.Decrease;
        }

        ChangeLightIntensity(myDir);
    }
Example #3
0
    void Update()
    {
        if (!sp.SerialPort.IsOpen)
        {
            sp.OpenSerialPort();
        }

        str    = sp.RawData;
        values = splitString(str);

        //uncomment for debug
        string s = "";

        foreach (int item in values)
        {
            s += item.ToString();
            s += ", ";
        }

        print("FIRST: " + s);


        originalScale = transform.localScale;

        if (values[0] >= scaleMinValue && originalScale.x <= 1)
        {
            StartCoroutine(Scale());
        }
    }
Example #4
0
    // Update is called once per frame
    void Update()
    {
        //catch if SP is closed, make sure it's open
        if (!sp.SerialPort.IsOpen)
        {
            sp.OpenSerialPort();
        }

        str       = sp.RawData;
        curValues = splitString(str);

        /* string s = "";
         *
         * foreach (int item in curValues)
         * {
         *    s += item.ToString();
         *    s += ", ";
         * }
         *
         *
         * print("FIRST: " + s);*/

        //init values with specific array member
        int o = 0;
        int c = 0;

        o = oldValues[3];
        c = curValues[3];

        //Timer

        if (o < c)
        {
            lightOn();

            print("INCREASE");
            oldValues = curValues;
        }
        if (o == c)
        {
            //lt.intensity = lt.intensity;
            lightOn();

            print("same");
            oldValues = curValues;
        }
        if (o > c)
        {
            lt.intensity = Mathf.Lerp(maxLight, minLight, t);
            t           += Time.deltaTime * 5;

            print("DECREASE");
            oldValues = curValues;
        }
    }
Example #5
0
    // Method that can be used to both open
    // and close the serial port.

    public void OpenClosePort()
    {
        if (unitySerialPort.SerialPort == null)
        {
            unitySerialPort.OpenSerialPort(); return;
        }

        switch (unitySerialPort.SerialPort.IsOpen)
        {
        case true: unitySerialPort.CloseSerialPort(); break;

        case false: unitySerialPort.OpenSerialPort(); break;
        }

        // Update the buttons text display

        if (ComButton != null)
        {
            ComButton.text = PortOpenStatus;
        }
    }
Example #6
0
    // Use this for initialization
    void Start()
    {
        //init arrays
        curValues = new int[16];  // numbers is a 16-element array
        oldValues = curValues;

        //init port
        sp = UnitySerialPort.Instance;
        sp.OpenSerialPort();

        lt = GetComponent <Light>();
    }
Example #7
0
    void Update()
    {
        if (!sp.SerialPort.IsOpen)
        {
            sp.OpenSerialPort();
        }

        str    = sp.RawData;
        values = splitString(str);

        //uncomment for debug
        string s = "";

        foreach (int item in values)
        {
            s += item.ToString();
            s += ", ";
        }


        print("FIRST: " + s);
        //print("SECOND: " + s);
    }
Example #8
0
    // Update is called once per frame
    void Update()
    {
        if (!sp.SerialPort.IsOpen)
        {
            sp.OpenSerialPort();
        }

        str       = sp.RawData;
        curValues = splitString(str);



        if (Time.time >= timer)
        {
            oldValues = curValues;

            timer += period;



            /*
             * if (curValues[0] > oldValues[0])
             * {
             *
             *  Debug.Log("INCREASE");
             * }
             *
             *
             * if (curValues[0] < oldValues[0])
             * {
             *
             *  Debug.Log("DECREASE");
             * }
             */
        }
    }
Example #9
0
    // Update is called once per frame
    void Update()
    {
        if (!sp.SerialPort.IsOpen)
        {
            sp.OpenSerialPort();
        }

        str    = sp.RawData;
        values = splitString(str);

        //uncomment for debug
        string s = "";

        foreach (int item in values)
        {
            s += item.ToString();
            s += ", ";
        }

        print("FIRST: " + s);
        //Debug.Log(mode + " : " + this.gameObject.name + " : " + this.GetComponent<Renderer>().material.color.a);

        if (values[0] > 25)

        {
            r += Time.deltaTime * changingSpeed;
            r  = Mathf.Clamp(r, 0f, 1f);
            Debug.Log("r;" + r);
        }

        if (values[0] <= 25)
        {
            r -= Time.deltaTime * changingSpeed;
            r  = Mathf.Clamp(r, 0f, 1f);
            Debug.Log("r;" + r);
        }

        if (values[0] > 27)
        {
            g += Time.deltaTime * changingSpeed;
            g  = Mathf.Clamp(g, 0f, 1f);
            Debug.Log("g;" + g);
        }

        if (values[0] <= 27)
        {
            g -= Time.deltaTime * changingSpeed;
            g  = Mathf.Clamp(g, 0f, 1f);
            Debug.Log("g;" + g);
        }

        if (values[0] > 29)

        {
            b += Time.deltaTime * changingSpeed;
            b  = Mathf.Clamp(b, 0f, 1f);
            Debug.Log("b;" + b);
        }

        if (values[0] <= 29)
        {
            b -= Time.deltaTime * changingSpeed;
            b  = Mathf.Clamp(b, 0f, 1f);
            Debug.Log("b;" + b);
        }

        //if (Input.GetKey(KeyCode.J))
        //if (Input.GetKey(KeyCode.K))

        // 앞에 오브젝트가 있어서 FadeMode가 Stop인 상태일 때,
        // 앞의 오브젝트의 알파가 0.5 이하인지 확인


        this.GetComponent <Renderer>().material.color = new Color(r, g, b, a);
    }