Answers for "arduino ble led dimmer code"

0

arduino ble led dimmer code

btnPaired = (Button)findViewById(R.id.button);devicelist = (ListView)findViewById(R.id.listView);
Posted by: Guest on January-09-2021
0

arduino ble led dimmer code

private void msg(String s)   {             Toast.makeText(getApplicationContext(),s,Toast.LENGTH_LONG).show();   }
Posted by: Guest on January-09-2021
0

arduino ble led dimmer code

myBluetooth = BluetoothAdapter.getDefaultAdapter();if(myBluetooth == null)   {     //Show a mensag. that thedevice has no bluetooth adapter     Toast.makeText(getApplicationContext(), "Bluetooth Device Not Available", Toast.LENGTH_LONG).show();    //finish apk     finish();   }
  else   {    if (myBluetooth.isEnabled())        { }    else    {
	//Ask to the user turn the bluetooth on 
	Intent turnBTon = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
	startActivityForResult(turnBTon,1);    }}
Posted by: Guest on January-09-2021
0

arduino ble led dimmer code

import android.bluetooth.BluetoothSocket;
import android.content.Intent;import android.view.View;import android.widget.Button;import android.widget.SeekBar;import android.widget.TextView;import android.widget.Toast;import android.app.ProgressDialog;import android.bluetooth.BluetoothAdapter;import android.bluetooth.BluetoothDevice;import android.os.AsyncTask;import java.io.IOException;import java.util.UUID;
Posted by: Guest on January-09-2021
0

arduino ble led dimmer code

import android.widget.Button;
import android.widget.ListView;
Posted by: Guest on January-09-2021
0

arduino ble led dimmer code

private class ConnectBT extends AsyncTask<Void, Void, Void>  // UI thread{
    private boolean ConnectSuccess = true; //if it's here, it's almost connected    @Override
    protected void onPreExecute()
    {
        progress = ProgressDialog.show(ledControl.this, "Connecting...", "Please wait!!!");  //show a progress dialog
    }    @Override
    protected Void doInBackground(Void... devices) //while the progress dialog is shown, the connection is done in background
    {
        try
        {
            if (btSocket == null || !isBtConnected)
            {
             myBluetooth = BluetoothAdapter.getDefaultAdapter();//get the mobile bluetooth device
             BluetoothDevice dispositivo = myBluetooth.getRemoteDevice(address);//connects to the device's address and checks if it's available
             btSocket = dispositivo.createInsecureRfcommSocketToServiceRecord(myUUID);//create a RFCOMM (SPP) connection
             BluetoothAdapter.getDefaultAdapter().cancelDiscovery();
             btSocket.connect();//start connection
            }
        }
        catch (IOException e)
        {
            ConnectSuccess = false;//if the try failed, you can check the exception here
        }
        return null;
    }
    @Override
    protected void onPostExecute(Void result) //after the doInBackground, it checks if everything went fine
    {
        super.onPostExecute(result);        if (!ConnectSuccess)
        {
            msg("Connection Failed. Is it a SPP Bluetooth? Try again.");
            finish();
        }
        else
        {
            msg("Connected.");
            isBtConnected = true;
        }
        progress.dismiss();
    }
}
Posted by: Guest on January-09-2021
0

arduino ble led dimmer code

private void Disconnect(){
    if (btSocket!=null) //If the btSocket is busy
    {
        try
        {
            btSocket.close(); //close connection
        }
        catch (IOException e)
        { msg("Error");}
    }
    finish(); //return to the first layout}
Posted by: Guest on January-09-2021
0

arduino ble led dimmer code

private void pairedDevicesList(){
    pairedDevices = myBluetooth.getBondedDevices();
    ArrayList list = new ArrayList();    if (pairedDevices.size()>0)
    {
        for(BluetoothDevice bt : pairedDevices)
        {
            list.add(bt.getName() + "\n" + bt.getAddress()); //Get the device's name and the address
        }
    }
    else
    {
        Toast.makeText(getApplicationContext(), "No Paired Bluetooth Devices Found.", Toast.LENGTH_LONG).show();
    }    final ArrayAdapter adapter = new ArrayAdapter(this,android.R.layout.simple_list_item_1, list);
    devicelist.setAdapter(adapter);
    devicelist.setOnItemClickListener(myListClickListener); //Method called when the device from the list is clicked}
Posted by: Guest on January-09-2021
0

arduino ble led dimmer code

btnPaired.setOnClickListener(new View.OnClickListener() {            @Override            public void onClick(View v)            {                pairedDevicesList(); //method that will be called            }        });
Posted by: Guest on January-09-2021
0

arduino ble led dimmer code

Button btnPaired;ListView devicelist;
Posted by: Guest on January-09-2021

Browse Popular Code Answers by Language