using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Uduino;
using UnityEngine.XR;
using UnityEngine.XR.Interaction.Toolkit;


public class ServoM6 : MonoBehaviour
{
    public int servoPin = 5;
    [Range(0, 180)]
    public int servoAngle = 90;
    private int prevServoAngle = 90;
    public GameObject Rcontroller;
    private float angle;
    private Vector3 rotate;

    void Start()
    {



    }

    void Update()
    {
        rotate = Rcontroller.transform.rotation.eulerAngles;
        if (rotate.z < 180)
        {
            angle = 90 - rotate.z;
        }
        if(rotate.z > 180)
        {                     
            angle = 450 - rotate.z;
        }
        servoAngle = Mathf.RoundToInt(angle);

        if (servoAngle != prevServoAngle) // Condition to not send data each frame 
        {
            UduinoManager.Instance.sendCommand("movewristver",servoAngle);
            prevServoAngle = servoAngle;
        }
    }
}