示例#1
0
 // Update is called once per frame
 void Update()
 {
     posx = GameObject.Find("Cube").transform.position.x;
     pwm  = posx.ToString();
     serial.WriteToArduino("PWM");
     serial.WriteToArduino(pwm);
 }
示例#2
0
    void FixedUpdate()
    {
        if (generator.dead)
        {
            StartCoroutine(Waiting());
        }
        if (timer >= 2 && !initialized)
        {
            initialized = true;
            communicator.WriteToArduino("N8\n");
        }
        else if (!initialized)
        {
        }
        {
            timer += Time.deltaTime;
        }

        if (initialized)
        {
            if (oldPower != Mathf.Clamp(generator.maxLitRooms, 2, 7))
            {
                communicator.WriteToArduino("P" + Mathf.Clamp(generator.maxLitRooms, 2, 7) + "\n");
                oldPower = Mathf.Clamp(generator.maxLitRooms, 2, 7);
            }

            communicator.WriteToArduino("S\n");
            string inPut = communicator.ReadFromArduino(50);
            Debug.Log(inPut);
            if (inPut != null && inPut != "INVALID")
            {
                char[] charArray = inPut.ToCharArray();
                for (int i = 11; i < charArray.Length; i++)
                {
                    //Debug.Log(charArray[i]);
                    if (charArray[i] == '1')
                    {
                        generator.triggerRooms[i - 11].isLit = true;
                    }
                    if (charArray[i] == '0')
                    {
                        generator.triggerRooms[i - 11].isLit = false;
                    }
                }
            }
        }
    }
示例#3
0
 private void FixedUpdate()
 {
     timer += Time.fixedDeltaTime;
     if (timer > updateInterval)
     {
         if (sendData && arduinoConnector && arduinoConnector.useArduino)
         {
             arduinoConnector.WriteToArduino(allLEDs);
         }
         timer = 0f;
     }
 }
示例#4
0
        private void sendToSerial(string code) //tady davam serial pro arduino
        {
            Debug.Log(code);
            if (connector == null)
            {
                connector = gameObject.AddComponent <ArduinoConnector>();
            }

            string sound;

            switch (code)
            {
            case ("SVETLO25"):
                sound = "SoundAura";
                break;

            case ("SVETLO50"):
                sound = "SoundMagic";
                break;

            case ("SVETLO75"):
                sound = "SoundMagic";
                break;

            case ("SVETLO"):
                sound = "SoundUnlock";
                break;

            default:
                sound = "SoundFail";
                GameObject.Find("SoundAura").GetComponent <AudioSource>().Stop();
                break;
            }


            GameObject.Find("SoundMagic").GetComponent <AudioSource>().Stop();
            GameObject.Find("SoundFail").GetComponent <AudioSource>().Stop();


            GameObject.Find(sound).GetComponent <AudioSource>().Play();

            connector.WriteToArduino(code);
        }
    void Update()
    {
        //If the game is over and the player has pressed some input...
        if (gameOver && Input.GetMouseButtonDown(0))
        {
            //...reload the current scene.
            SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
        }

        // Add Arduino
        connect.WriteToArduino("PING");
        string s = connect.ReadFromArduino(10000);

        //Debug.Log(s);
        string[] block = s.Split(null);
        dataX = int.Parse(block[0]);
        dataY = int.Parse(block[1]);
        dataW = int.Parse(block[2]);
        dataH = int.Parse(block[3]);

        // Log file for data received from Arduino > output in the console of Unity3D
        //Debug.Log("x: " + dataX + " y: " + dataY + " w: " + dataW + " h: " + dataH);
        //Debug.Log("value1: " + (dataX - dataW) + " value2: " + (dataY - dataH));

        // If size of block bigger than 15, then it is recognized as a pushing interaction
        // This information read by 'Bird.cs'
        if (dataX - dataW > 15 && dataY - dataH > 15)
        {
            pushing = true;
        }
        else
        {
            pushing = false;
        }

        //Debug.Log(pushing);
    }
示例#6
0
    void Update()
    {
        string value = arduino.ReadFromArduino(); //Read the information

        if (value == null)                        //if data is null [...]
        {
            // [...] then do nothing
        }
        else
        {
            vec3 = value.Split(','); //My arduino script returns a 4 part value (IE: 0,0,18,100,0,1)
            //////////////////////////////////////////////////////////////  x,y,speed,rudder,button1,button2


            if (vec3[0] != "" && vec3[1] != "" && vec3[2] != "" && vec3[3] != "" && vec3[4] != "" && vec3[5] != "") //Check if all values are recieved
            {
                predkoscNastawa.value = float.Parse(vec3[2]);                                                       //parse spped value from serial
                pletwaNastawa.value   = float.Parse(vec3[3]);                                                       //parse rudder value from serial
                CamX = 19 + float.Parse(vec3[0]);                                                                   //parse X axis value
                CamY = 90 + float.Parse(vec3[1]);                                                                   //parse Y axis value
                Kamera.transform.rotation = Quaternion.Euler(CamX, CamY + COG, 0);                                  //rotates camera

                if (int.Parse(vec3[4]) == 0 && pause == 0)                                                          //pause simulation
                {
                    Time.timeScale = 0;
                    pause          = 1;
                }

                if (int.Parse(vec3[5]) == 0 && pause == 1)  //unpause simulation
                {
                    Time.timeScale = 1;
                    pause          = 0;
                }
            }
        }

        predkosc.text = predkoscNastawa.value.ToString() + " %";
        pletwa.text   = pletwaNastawa.value.ToString() + " °";

        if (predkoscAktualna != predkoscNastawa.value * predkoscMax / 100)
        {
            predkoscAktualna    = Mathf.Lerp(predkoscAktualna, (predkoscMax * predkoscNastawa.value) / 100, 0.05f * Time.deltaTime);
            predkoscAktHUD.text = predkoscAktualna.ToString("0.0") + " kn";
        }

        pletwaAkt        = Mathf.MoveTowards(pletwaAkt, pletwaNastawa.value, 1f * Time.deltaTime);
        predkoscAktualna = Mathf.MoveTowards(predkoscAktualna, (predkoscMax * predkoscNastawa.value) / 100, 0.05f * Time.deltaTime);

        if (predkoscAktualna != 0)
        {
            ROT           += (K * (pletwaAkt) - ROT) * Time.deltaTime;
            ROTAktHUD.text = ROT.ToString("0.0") + "  °/s";
            COG           += ROT * Time.deltaTime;
            COGAktHUD.text = COG.ToString("0.0") + "  °";
            {
                x += predkoscAktualna * Time.deltaTime * Mathf.Sin(COG * Mathf.PI / 180);
                z += predkoscAktualna * Time.deltaTime * Mathf.Cos(COG * Mathf.PI / 180);
                transform.position    = new Vector3(2100 + z, 500, 1900 - x);
                transform.rotation    = Quaternion.Euler(0, COG, 0);
                wychylenieAktHUD.text = pletwaAkt.ToString("0") + " °";
            }
        }
        arduino.WriteToArduino(predkoscAktHUD.text);
    }