void Start() { try{ x = ""; BTHelper = BluetoothHelper.GetInstance("HC-05"); BTHelper.setLengthBasedStream(); BTHelper.OnConnected += OnBluetoothConnected; //OnBluetoothConnected is a function defined later on // BTHelper.OnDataReceived += () => { // //this is called when you receive data FROM your arduino // string receivedData; // receivedData = BTHelper.Read(); // returns a string // //since you are sending an array, convert the string to array : // char[] data = receivedData.ToCharArray(); // //do Whatever you want // }; BTHelper.OnDataReceived += (helper) => { try{ string xx = helper.Read(); char[] data = xx.ToCharArray(); if (data.Length != 3) { return; } int i = 0; if (data[0] != 'S') { return; } if (data[1] == 'E') { i = 1; } if (data[2] > 7) { return; } spheres[data[2] - 2].GetComponent <Renderer>().material = materials[i]; }catch (Exception ex) { x += ex.Message; } }; }catch (Exception ex) { Debug.Log(ex); x = ex.ToString(); } }
void Start() { min [0] = 1023; min [1] = 1023; min [2] = 1023; min [3] = 1023; min [4] = 1023; max [0] = 0; max [1] = 0; max [2] = 0; max [3] = 0; max [4] = 0; deviceName = "HC05"; //bluetooth should be turned ON; try { bluetoothHelper = BluetoothHelper.GetInstance(deviceName); bluetoothHelper.OnConnected += OnConnected; bluetoothHelper.OnConnectionFailed += OnConnectionFailed; bluetoothHelper.OnDataReceived += OnMessageReceived; //read the data bluetoothHelper.setLengthBasedStream(); if (bluetoothHelper.isDevicePaired()) { sphere.GetComponent <Renderer>().material.color = Color.blue; } else { sphere.GetComponent <Renderer>().material.color = Color.grey; } } catch (Exception ex) { sphere.GetComponent <Renderer>().material.color = Color.yellow; Debug.Log(ex.Message); text.text = ex.Message; } }
// [DllImport ("TestPlugin")] // private static extern int getNumber(); void Start() { try { // Debug.Log(getNumber()); BluetoothHelper.BLE = false; //use Bluetooth Low Energy Technology bluetoothHelper = BluetoothHelper.GetInstance(); bluetoothHelper.OnConnected += OnConnected; bluetoothHelper.OnConnectionFailed += OnConnectionFailed; bluetoothHelper.OnDataReceived += OnMessageReceived; //read the data bluetoothHelper.OnScanEnded += OnScanEnded; // bluetoothHelper.setTerminatorBasedStream("\n"); bluetoothHelper.setLengthBasedStream(); // if(bluetoothHelper.isDevicePaired()) // sphere.GetComponent<Renderer>().material.color = Color.blue; // else // sphere.GetComponent<Renderer>().material.color = Color.grey; // bluetoothHelper.ScanNearbyDevices(); if (!bluetoothHelper.ScanNearbyDevices()) { text.text = "cannot start scan"; sphere.GetComponent <Renderer>().material.color = Color.black; // bluetoothHelper.setDeviceAddress("00:21:13:02:16:B1"); bluetoothHelper.setDeviceName("HC-08"); bluetoothHelper.Connect(); } else { text.text = "start scan"; // sphere.GetComponent<Renderer>().material.color = Color.green; } } catch (Exception ex) { sphere.GetComponent <Renderer>().material.color = Color.yellow; Debug.Log(ex.ToString()); text.text = ex.Message; } }
void Start() { lauf = false; greif = false; info = false; for (int i = 0; i <= 5; i++) // Setzt die Begrenzungs Werte { zu[i] = 0; auf[i] = 1023; } deviceName = "HC05"; //Wichtig: Bluethoot AN ! try { bluetoothHelper = BluetoothHelper.GetInstance(deviceName); bluetoothHelper.OnConnected += OnConnected; bluetoothHelper.OnConnectionFailed += OnConnectionFailed; bluetoothHelper.OnDataReceived += OnMessageReceived; //list die Daten ein bluetoothHelper.setLengthBasedStream(); if (bluetoothHelper.isDevicePaired()) { sphere.GetComponent <Renderer>().material.color = Color.blue; } else { sphere.GetComponent <Renderer>().material.color = Color.grey; } } catch (Exception ex) { sphere.GetComponent <Renderer>().material.color = Color.yellow; Debug.Log(ex.Message); text.text = ex.Message; } }