Hello everyone, i'm sorry for the mistake, it won't happen again, next time i'll put my question in the right section. I've done some debugging and i've come to very strange behaviour of my code. I'll explain now. I have a variable strpom, in which i store the data, that i receive via UART. strpomForming is a function that throws out the endesireble bytes that come on UART and gives me the form of the string that i want. Now i convert my variable strpom in pomString, so i can use the function substring to decompose my UART message. In the if else structure i print the data on LCD display. I have variables AP,DS,DP,AS,GV which are also String type and i use them to store some parts of my main string. I also have the piece of code that write my variable pomString into the SD card. Now when i don't have the else part in my code the writing into the SD card works without any problem. But when i have the else part and all those String variables the writing doesn't work. The if-else and the if for writing in the SD card are in the loop. And the writing on the SD card is controled by the button. Could you help me to figure out why by adding one part of the code, the other doesn't work ?
Thank You
unsigned char strpom[65];
Serial.readBytes(strpom, 65);
strpomForming(strpom);
pomString = String((char *)strpom);
if((pomString.substring(0, 2) != "[B")){
lcd.setCursor(0, 0);
lcd.print(" ");
lcd.setCursor(1, 0);
lcd.print(lcdStrPage1a);
lcd.setCursor(0, 1);
lcd.print(" ");
lcd.setCursor(0, 2);
lcd.print(" ");
lcd.setCursor(1, 2);
lcd.print(lcdStrPage2a);
lcd.setCursor(0, 3);
lcd.print(" ");
}else{
tempStr = pomString.substring(pomString.indexOf("[B") + 2, pomString.indexOf("[C");
voltage = float(tempStr.toInt());
voltage = voltage / 1000;
AP = pomString.substring(pomString.indexOf("[C") + 1, pomString.indexOf("[E") - 1);
DP = pomString.substring(pomString.indexOf("[E") + 1, pomString.indexOf("[D") - 1);
if(pomString.indexOf("[V") == -1){
FW = pomString.substring(pomString.indexOf("[M") + 2, pomString.indexOf(']'));
}else{
FW = pomString.substring(pomString.indexOf("[V") + 2, pomString.indexOf(']'));
}
AS = pomString.substring(pomString.indexOf("[D") + 1, pomString.indexOf("[A") - 1);
DS = pomString.substring(pomString.indexOf("[A") + 1, pomString.indexOf("[G") - 1);
GV = pomString.substring(pomString.indexOf("[G") + 2, pomString.indexOf("[S") - 1);
pomGValue = GV.toInt();
indexAcc = pomString.indexOf("[X");
tempStr2 = pomString.substring(indexAcc + 2, indexAcc + 6);
accX = (tempStr2.toInt());
indexAcc = pomString.indexOf("[Y");
tempStr2 = pomString.substring(indexAcc + 2, indexAcc + 6);
accY = (tempStr2.toInt());
indexAcc = pomString.indexOf("[Z");
tempStr2 = pomString.substring(indexAcc + 2, indexAcc + 6);
accZ = (tempStr2.toInt());
if (abs(1500-accX)>abs(1500-accY)){
if (abs(1500-accX)>abs(1500-accZ)){
tempStr3 = String(accX);
}else{
tempStr3 = String(accZ);
}
}else{
if (abs(1500-accY)>abs(1500-accZ)){
tempStr3 = String(accY);
}else{
tempStr3 = String(accZ);
}
}
lcd.setCursor(0, 0);
lcd.print(" ");
lcd.setCursor(1, 0);
lcd.print(lcdStrPage1a);
lcd.setCursor(0, 1);
lcd.print(" ");
if(voltage < 10.00){
lcd.setCursor(2, 1);
lcd.print((String)voltage);
}else{
lcd.setCursor(1, 1);
lcd.print((String)voltage);
}
lcd.setCursor(6, 1);
lcd.print(" " + AP + " " + DP + " " + FW + " ");
lcd.setCursor(0, 2);
lcd.print(" ");
lcd.setCursor(1, 2);
lcd.print(lcdStrPage2a);
lcd.setCursor(0, 3);
lcd.print(" ");
lcd.setCursor(2, 3);
lcd.print(tempStr3);
lcd.setCursor(6, 3);
if(GV.toInt() > 90){
lcd.print(" " + DS + " " + AS + " " + GV + " ");
}else{
lcd.print(" " + DS + " " + AS + " " + GV + " ");
}
}
if(SD.begin(chipSelect)){
myFile = SD.open("testbox.txt", FILE_WRITE);
myFile.println(pomString);
myFile.close();
onceWritten = 1;
}