Saturday, 7 September 2013

Unexpeted output on Arduino

Unexpeted output on Arduino

I'm using Leonardo and I want to print a message when I type ">" and "<".
Something like >my_message<.
I have the following code but it is not working like I was expecting
(nothing happens). How can I fix this or is there a better way to do this?
String txtMsg = ""; // a string for incoming text
void setup() {
Serial.begin(9600);
while (!Serial); // wait for serial port to connect. Needed for Leonardo
only
}
void loop() {
// add any incoming characters to the String:
while (Serial.available() > 0) {
char inChar = Serial.read();
txtMsg += inChar;
char StartDelimiter = txtMsg.charAt(0);
int endDel = txtMsg.length() - 1;
char EndDelimiter = txtMsg.charAt(endDel);
if (StartDelimiter == '>' && EndDelimiter == '<') {
Serial.println(txtMsg);
}
}
}

No comments:

Post a Comment