Skip to content

Instantly share code, notes, and snippets.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#121212"
android:orientation="vertical">
<RelativeLayout
android:layout_marginTop="60dp"
android:layout_width="match_parent"
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:innerRadiusRatio="2.5"
android:shape="ring"
android:thickness="4dp"
android:useLevel="false">
<solid android:color="#b4b4b4"/>
<corners
android:bottomLeftRadius="60dp"
android:bottomRightRadius="60dp"
android:topLeftRadius="60dp"
#include<SoftwareSerial.h>
#define led D5
SoftwareSerial mySerial(D7,D8);
char command;
String string;
import androidx.appcompat.app.AppCompatActivity;
import android.app.ProgressDialog;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothSocket;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
private class ConnectBT extends AsyncTask<Void, Void, Void>
{
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
}
private void Disconnect()
{
if (btSocket!=null) //If the btSocket is busy
{
try
{
btSocket.close(); //close connection
Toast.makeText(getApplicationContext(),"Connection closed successfully",Toast.LENGTH_SHORT).show();
}
onButton = (Button) findViewById(R.id.onButton);
offButton = (Button) findViewById(R.id.offButton);
disconnectButton = (Button) findViewById(R.id.disconnectButton);
Intent newint = getIntent();
address = newint.getStringExtra("DEVICE_ADDRESS");onButton.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
BluetoothAdapter myBluetooth = null;
BluetoothSocket btSocket = null;
Button onButton, offButton, disconnectButton;
private ProgressDialog progress;
String address=null;
static final UUID myUUID = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB");
private boolean isBtConnected = false;
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.util.Log;