I'm trying to built an Android application in MIT App Inventor 2.
This is my design
This is my code blocks
My purpose is; when I click somewhere on the color wheel; getting the coordinates of the place that I clicked (black ball) and get its RGB values.
It works perfectly on phone screen, it shows the values. But the problem is; when I try to import the rgb values to Firebase, the values are like in this format in this picture
As you see, the text formats in their boxes are like: "\"101\""
But I want: 101
only. Because I will get the values to my NodeMCU ESP8266 for blink a RGB LED. I will insert these values to analogWrite(pin,value)
function.
Where is my fault in MIT App Inventor Block screen? Is there any solution in there? Or can you give me suggestion about it for ESP8266 code part (like split the text or something) ?
You can add this line
String b_fir = Firebase.getString("B");
String str_b_fir = getStringPartByNr(b_fir, '"', 1);
int int_b_fir = str_b_fir.toInt();
You can add this function under the loop
String getStringPartByNr(String data, char separator, int index)
{
// spliting a string and return the part nr index
// split by separator
int stringData = 0; //variable to count data part nr
String dataPart = ""; //variable to hole the return text
for(int i = 0; i<data.length()-1; i++) { //Walk through the text one letter at a time
if(data[i]==separator) {
//Count the number of times separator character appears in the text
stringData++;
}else if(stringData==index) {
//get the text when separator is the rignt one
dataPart.concat(data[i]);
}else if(stringData>index) {
//return text and stop if the next separator appears - to save CPU-time
return dataPart;
break;
}
}
//return text if this is the last part
return dataPart;
}