HI. Im making an app to control some LEDs, and it works with bluetooth so it needs to be able to allow the user to change the MAC direction of the controller. the thing is that there are 2 problems; When Converting the String lines into a normal string with .toString(); it returns something like this: [Ljava.lang.String;@1b4163d. And the second problem, when I write saveStrings(“mac.txt”, lines);, it doesnt change anything. here is the code:
PImage img1;
PImage img2;
PImage img3;
PImage img4;
PImage img5;
PImage img6;
PImage img7;
PImage img8;
PImage img9;
PImage img10;
PImage img11;
String typing = "";
String saved = "";
boolean sett = false;
import java.io.File;
int si = 0;
int igri = 0;
String elstr="";
boolean keyboard = false;
boolean interm = false;
boolean error = false;
import ketai.net.bluetooth.*;
import android.os.Bundle;
String device_name = "ESP32";
String device_mac = "";
KetaiBluetooth bt;
void setup() {
String[] lines = loadStrings("mac.txt");
device_mac = lines.toString();
img1 = loadImage("img1.png");
img2 = loadImage("img2.png");
img3 = loadImage("img3.png");
img4 = loadImage("img4.png");
img5 = loadImage("img5.png");
img6 = loadImage("img6.png");
img7 = loadImage("img7.png");
img8 = loadImage("img8.png");
img9 = loadImage("img9.png");
img10 = loadImage("img10.png");
img11 = loadImage("img11.png");
fullScreen();
orientation(LANDSCAPE);
noStroke();
fill(0);
bt = new KetaiBluetooth(this);
bt.getPairedDeviceNames();
bt.start();
bt.connectToDeviceByName(device_name);
String awewo = lines.toString();
boolean porque = awewo.contains(":");
print(lines);
print(porque);
print(awewo);
}
/*String str = "igri";
byte[] data = str.getBytes();
bt.writeToDeviceName(device_name, data);
delay(1000);
background(255,0,0);
image(led1, 670, 100,130,100);
*/
void draw(){
if(!sett){
drawmenu();}
else{setting();}
int indent = 25;
if(mousePressed){
si = mouseX;
igri = mouseY;
print(si," ",igri);
matense(si,igri);
}
}
void drawmenu(){
if(error){
background(255,0,0);
text("No hay una direccion MAC puesta!",100,300);
setting();
}
else{
fill(255,255,255);
background(75,59,59);
textSize(60);
text("Control", 70, 70);
text("Paleta de colores", 500, 70);
text("Extras", 1200, 70);
image(img1,100,80,130,130);
image(img2,100,230,130,130);
if(interm){
image(img7,100,370,130,130);
image(img8,100,510,130,130);
}
else{
image(img3,100,370,130,130);
image(img4,100,510,130,130);
}
image(img5,1200,80,130,130);
image(img6,1200,230,130,130);
image(img9,1200,370,130,130);
image(img10,1200,510,130,130);
image(img11,1400,30,100,100);
fill(255,0,0);
rect(350,80,130,130);
fill(0,255,0);
rect(350,230,130,130);
fill(0,0,255);
rect(350,370,130,130);
fill(255,255,255);
rect(350,510,130,130);
//a
fill(247,105,10);
rect(490,80,130,130);
fill(31,240,81);
rect(490,230,130,130);
fill(31,85,240);
rect(490,370,130,130);
//b
fill(240,167,31);
rect(630,80,130,130);
fill(31,172,240);
rect(630,230,130,130);
fill(165,23,116);
rect(630,370,130,130);
//c
fill(255,175,0);
rect(775,80,130,130);
fill(8,188,206);
rect(775,230,130,130);
fill(232,12,133);
rect(775,370,130,130);
//d
fill(234,255,15);
rect(915,80,130,130);
fill(9,107,180);
rect(915,230,130,130);
fill(255,3,167);
rect(915,370,130,130);
}
}
void matense(int x, int y){
String str = "";
if(x>=100 && x<=230){
if(y>=80 && y<=220){str="a";}
if(y>=230 && y<=360){str="b";}
if(y>=370 && y<=500){if(interm){str="5";}else{str="c";}}
if(y>=510 && y<=640){if(interm){str="7";}else{str="d";}}
}
if(x>=490 && x<=620){
interm = false;
if(y>=80 && y<=220){str="e";}
if(y>=230 && y<=360){str="f";}
if(y>=370 && y<=500){str="g";}
if(y>=510 && y<=640){str="h";}
}
if(x>=630 && x<=760){
interm = false;
if(y>=80 && y<=220){str="i";}
if(y>=230 && y<=360){str="j";}
if(y>=370 && y<=500){str="k";}
if(y>=510 && y<=640){str="l";}
}
if(x>=775 && x<=905){
interm = false;
if(y>=80 && y<=220){str="m";}
if(y>=230 && y<=360){str="n";}
if(y>=370 && y<=500){str="o";}
if(y>=510 && y<=640){str="p";}
}
if(x>=915 && x<=1045){
interm = false;
if(y>=80 && y<=220){str="q";}
if(y>=230 && y<=360){str="r";}
if(y>=370 && y<=500){str="s";}
if(y>=510 && y<=640){str="t";}
}
if(x>=350 && x<=480){
interm = false;
if(y>=80 && y<=220){str="v";}
if(y>=230 && y<=360){str="w";}
if(y>=370 && y<=500){str="x";}
if(y>=510 && y<=640){str="y";}
}
if(x>=1200 && x<=1330){
interm = true;
if(y>=80 && y<=220){str="2";}
if(y>=230 && y<=360){str="3";}
if(y>=370 && y<=500){str="4";}
if(y>=510 && y<=640){str="8";}
}
if(x>=1400 && x<=1500){
if(y>=30 && y<=130){
sett = true;
}}
print(str);
byte[] data = str.getBytes();
bt.writeToDeviceName(device_name, data);
delay(100);
}
void setting(){
int indent = 25;
fill(0,0,255);
rect(230,80,815,560);
fill(255,255,255);
fill(255,255,0);
rect(250,200,50,50);
fill(0,255,0);
rect(250,150,50,50);
fill(255,0,0);
rect(995,150,50,50);
text("Configuracion",230,140);
textSize(40);
fill(0,255,0);
text("Introduce la nueva Direccion MAC en \n minuscula para conectarse al ESP32. \n La MAC puede ser vista en el \n menu de la pantalla en 'CON' ",230,470);
textSize(60);
fill(255,255,255);
text("Atras",900,600);
text("Nueva mac: "+ saved,230,400);
text("<-- Abrir teclado",300,250);
text("<-- Borrar Guardar -->",300,200);
textSize(60);
text("MAC:" + typing,230,300);
if(mousePressed){
si = mouseX;
igri = mouseY;
}
if(mouseX >= 995 && mouseX <= 1040 && mouseY >= 150 && mouseY <= 200){
String[] lines = loadStrings("mac.txt");
if(lines.length>1)
lines[1] = saved;
saveStrings("mac.txt", lines);
print("Guardado: "+saved);
}
if (mouseX >= 250 && mouseX <= 300){
if(mouseY >= 200 && mouseY <= 250){
if (!keyboard) {
openKeyboard();
keyboard = true;
}
}
if(mouseY >= 150 && mouseY <= 200){
typing = "";
saved = "";
mouseY = mouseY + 100;
}
}
else {
closeKeyboard();
keyboard = false;
}
if(si>=900&&si<=1045){
if(igri>=580&&igri<=600){
sett=false;
}
}
}
void keyPressed() {
// If the return key is pressed, save the String and clear it
if (key == '\n' ) {
String my_new_str = typing.replace(",", ":");
saved = my_new_str;
// A String can be cleared by setting it equal to ""
typing = "";
} else {
// Otherwise, concatenate the String
// Each character typed by the user is added to the end of the String variable.
typing = typing + key;
}
}