const byte numChars = 32;
char receivedChars[numChars]; // an array to store the received data
char aus[2];
boolean newData = false;
void setup() {
Serial.begin(9600);
Serial.println("<Arduino ist bereit>");
}
void loop() {
recvWithEndMarker();
if (receivedChars[0] == 'q' && receivedChars[1] == 'q') {
Serial.println("Programm beendet, tschüss!");
delay(100);
exit(0);
}
}
void recvWithEndMarker() {
static byte ndx = 0;
char endMarker = '\n';
char rc;
while (Serial.available() > 0) {
rc = Serial.read();
if (rc != endMarker) {
receivedChars[ndx] = rc;
ndx++;
if (ndx >= numChars) {
ndx = numChars - 1;
}
} else {
receivedChars[ndx] = '\0'; // terminate the string
ndx = 0;
newData = true;
showNewData();
}
}
}
void showNewData() {
if (newData == true) {
Serial.print("");
Serial.println(receivedChars);
newData = false;
}
}