Hello!
I just got an Arduino Duemilanove a few weeks ago. I need some help with Serial Input. I want to be able to type in a string and have the serial monitor output it back. I was able to do it with numbers, but haven't been able to do it with a string without printing the increments. (ex. I input truck, output is t tr tru truc truck)
I want to be able to echo the string WITHOUT any header/footer chars, and, if possible, not have a set max. length.
What I want is:
Input: String Echoing Program Test
Output: String Echoing Program Test
But I only want the output to display once-- not repeat over and over again.
Here's what I have so far.
#include <WString.h>
int length;
char temp;
String outString = String(60);
int stat = 0;
void setup () {
Serial.begin(115200);
Serial.flush();
}
void loop () {
if(Serial.available() > 0 && stat == 0) {
delay(5);
length = Serial.available();
Serial.println(length);
}
else if (Serial.available() > 0) {
while(Serial.available() < 0) {
temp = Serial.read();
outString.append(temp);
stat = 1;
delay(5);
}
}
else if (stat == 1 && length == outString.length()) {
Serial.println(outString);
stat = 0;
outString = "";
Serial.flush();
}
}
By the way, I know C and C++.
Thanks in advance.