hi this code for member was helping what i need how to send 6 controlp5 sliders values to raduino
any one can help???
import android.Manifest;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Build.VERSION_CODES;
import processing.core.PConstants;
import android.app.Activity;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothSocket;
import android.content.Intent;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Set;
import java.util.UUID;
BluetoothAdapter mBluetoothAdapter;
BluetoothSocket mmSocket;
BluetoothDevice mmDevice;
OutputStream mmOutputStream;
InputStream mmInputStream;
Activity activity;
Permission bp, afl;
Thread runThread;
byte[] readBuffer;
int buffer_index;
boolean stop_thread, init = true;
String device_name = "HC-05";
boolean permissions_granted;
String Str = " ";
String t_str;
float a, increment = 0.04;
int y;
void setup() {
fullScreen();
orientation(LANDSCAPE);
bp = new Permission(this, "BLUETOOTH");
afl = new Permission(this, "ACCESS_FINE_LOCATION");
textAlign(CENTER);
textSize(70);
t_str = "Click to connect.";
textSize(12); // To create a "text width factor",
float twf = width/textWidth(t_str);
int f = 4; // Empericaly found
textSize(f*twf); // Making it proportional for other screen resolutions
}
void draw() {
if (init) {
background(150);
text(t_str, width/2, height/2);
strokeWeight(10);
noFill();
stroke(50);
rect(0, 0, width, height);
} else {
y = int(80 * sin(a));
a += increment;
if (a > TWO_PI) a = 0;
try {
sendData();
}
catch (IOException ex) {
}
}
}
void mousePressed () {
if (init) {
try {
init = false;
findBluetooth();
connect();
background(80);
text("Connecting to send.", width/2, height/2);
}
catch (IOException ex) {
println(ex);
}
}
}
void sendData() throws IOException {
mmOutputStream.write(y);
}
void findBluetooth() {
mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
if (mBluetoothAdapter == null) {
println("No bluetooth adapter available");
}
if (!mBluetoothAdapter.isEnabled()) {
Intent enableBluetooth = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
activity.startActivityForResult(enableBluetooth, 0);
}
Set<BluetoothDevice> pairedDevices = mBluetoothAdapter.getBondedDevices();
if (pairedDevices.size() > 0) {
print("Paired devices MAC Adress:");
printArray(pairedDevices);
for (BluetoothDevice device : pairedDevices) {
print("Paired devices by name:");
println(device.getName());
if (device.getName().equals(device_name)) {
mmDevice = device;
println("Bluetooth device name found");
break;
}
}
}
}
void connect() throws IOException {
UUID uuid = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB"); //Standard SerialPortService ID
mmSocket = mmDevice.createRfcommSocketToServiceRecord(uuid);
mmSocket.connect();
mmOutputStream = mmSocket.getOutputStream();
mmInputStream = mmSocket.getInputStream();
println("Bluetooth connected");
final byte delimiter = 33; //This is the ASCII code for a ! character
stop_thread = false;
buffer_index = 0;
readBuffer = new byte[1024];
runThread = new Thread(new Runnable() {
public void run() {
while (!Thread.currentThread().isInterrupted() && !stop_thread) {
try {
int bytesAvailable = mmInputStream.available();
if (bytesAvailable > 0) {
byte[] packetBytes = new byte[bytesAvailable];
mmInputStream.read(packetBytes);
for (int i = 0; i < bytesAvailable; i++) {
byte b = packetBytes[i];
if (b == delimiter) {
byte[] encodedBytes = new byte[buffer_index];
System.arraycopy(readBuffer, 0, encodedBytes, 0, encodedBytes.length);
final String data = new String(encodedBytes, "US-ASCII");
//plot(data);
buffer_index = 0;
} else {
readBuffer[buffer_index++] = b;
}
}
}
}
catch (IOException ex)
{
stop_thread = true;
}
}
}
}
);
runThread.start();
}
void closeBluetooth() throws IOException {
stop_thread = true;
mmOutputStream.close();
mmInputStream.close();
mmSocket.close();
println("Bluetooth stopped");
}
class Permission {
PApplet parent;
boolean requestedPortraitImage = false;
Permission(PApplet pParent, String permissionName) {
parent = pParent;
parent.requestPermission("android.permission."+permissionName, "onPermissionResult", this);
}
void onPermissionResult(boolean granted) {
if (granted) println("User did grant permission.");
else println("User did NOT grant permission.");
}
}
void onPause() {
try {
closeBluetooth();
}
catch (Exception ex) {
}
super.onPause();
}
void onStop () {
try {
closeBluetooth();
}
catch (Exception ex) {
}
super.onStop();
}
void onRestart() {
try {
findBluetooth();
connect();
}
catch (IOException ex) {
println(ex);
}
}