That's a program to take input from user and then test the string if it's palindrome or not .
the program runs fine with the led but why i can't output
Serial.println((String)s[i] +(String)" == "+(String)s[sz-i-1]);
it dousn't output anything and before this print , I tried the one with message "got here" but every time it lacks a letter like this
ot here
t here
here ....
that's my code
bool done = false;
String s ;
void setup() {
Serial.begin(9600);
pinMode(13, OUTPUT);
digitalWrite(13, HIGH );
s = "";
}
bool isPalindrome() {
int sz = s.length();
delay(1000);
/*Serial.println("got here " + sz);
delay(1000);*/
for (int i = 0 ; i < sz / 2 ; i++) {
delay(500);
Serial.println((String)s[i] +(String)" == "+(String)s[sz-i-1]);
if (s[i] != s[sz - i - 1]) {
return false ;
}
}
return true;
}
void loop() {
if (done) {
if (isPalindrome())digitalWrite(13, HIGH);
else digitalWrite(13, LOW);
done = false ;
}
}
void serialEvent() {
while (Serial.available()) {
char c = (char)Serial.read();
if (c == '\n')done = true;
else {
s += c;
//Serial.println(s);
}
}
}