Whoops my bad. But yes, please do look at it if you could.
*/
* The code is just not running twice.
*/
//Also, the code only accepts strings prefaced by 'a',
//otherwise it won't print it.
int txtMsgLength = 6;
String txtMsg = ""; // a string for incoming text
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect
}
// send an intro:
Serial.println("Code Initialized");
Serial.println();
}
void loop() {
if (Serial.available() > 0) {
for( int x = 0; x < 1; x++) {
char inChar = Serial.read();
txtMsg += inChar; // add any incoming characters to the String:
}
if (txtMsg.length() == txtMsgLength && txtMsg.startsWith("a") ) {
Serial.println(txtMsg);
txtMsg = "";
}
}
}