I'm developing on android with bluetooth LTE, I can send hex codes, but I send one code at time, so I need to send many informations in this way, how can I recognize a string and save the datas inside an array to parse it later?
Here is my sketch:
char c=' ';
String inString,one,check;
char inData[11];
char inChar;
int counter=0;
bool started = false;
bool ended = false;
byte index;
boolean NL = true;
const int LED1 = 6;
const int LED2 = 7;
const int LED3 = 2;
const int LED4 = 3;
const int LED5 = 4;
const int LED6 = 5;
void setup() {
Serial.begin(9600);
Serial.print("Sketch: "); Serial.println(__FILE__);
Serial.print("Uploaded: "); Serial.println(__DATE__);
Serial.println(" ");
BTserial.begin(9600);
Serial.println("BTserial started at 9600");
pinMode(LED1, OUTPUT);
pinMode(LED2, OUTPUT);
pinMode(LED3, OUTPUT);
pinMode(LED4, OUTPUT);
pinMode(LED5, OUTPUT);
pinMode(LED6, OUTPUT);
}
void loop() {
if (BTserial.available()>0)
{
Serial.print("bts: ");
Serial.println(BTserial.available());
c = BTserial.read();
check = String(c, HEX);
if(check=="ffbc"){
Serial.println("check");
index=0;
while (BTserial.available()>0){
inChar = BTserial.read();
check=String(inChar,HEX);
if(check != "0xfff3")
{
inData[index] = inChar;
index++;
}
}
for (int i=0;i<=11;i++){
one = String(inData[i], HEX);
Serial.print(i);Serial.print(": ");Serial.println(one);
};
}
if(check=="ffca"){
// Serial.write(c);
digitalWrite(LED1, !digitalRead(LED1));
}
if(check=="ffcb"){
//Serial.write(c);
digitalWrite(LED2, !digitalRead(LED2));
}
if(check=="ffcc"){
//Serial.write(c);
digitalWrite(LED3, !digitalRead(LED3));
}
if(check=="ffcd"){
//Serial.write(c);
digitalWrite(LED4, !digitalRead(LED4));
}
if(check=="ffce"){
// Serial.write(c);
digitalWrite(LED5, !digitalRead(LED5));
}
if(check=="ffcf"){
// Serial.write(c);
digitalWrite(LED6, !digitalRead(LED6));
}
}
}
Without the loop I can read all the single datas, but for my job it's not enough, to recognize the data applications I send a "sample string" to recognize the type of informations I want to send.