From e28e272926ea5415c5c111a849ce5ace25a2b54e Mon Sep 17 00:00:00 2001 From: Jim Martens Date: Wed, 3 Jun 2015 19:07:19 +0200 Subject: [PATCH] [ES] Fixed potential error with loop MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-óff-by: Jim Martens --- es/blatt3/uebung3-4/uebung3-4.ino | 40 ++++++++++++++++--------------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/es/blatt3/uebung3-4/uebung3-4.ino b/es/blatt3/uebung3-4/uebung3-4.ino index eafdb54..88325eb 100644 --- a/es/blatt3/uebung3-4/uebung3-4.ino +++ b/es/blatt3/uebung3-4/uebung3-4.ino @@ -88,25 +88,27 @@ void setup() { */ void loop() { if (Serial.available() > 0) { - char command[8]; - char currentChar; - int i = 0; - bool readable = true; - while (readable) { - currentChar = Serial.read(); - readable = (currentChar != -1); - command[i] = currentChar; - i++; - } - command[i] = '\0'; - - if (strcmp(command, "LED_on") == 0) { - digitalWrite(ledPin, HIGH); - } - else { - digitalWrite(ledPin, LOW); - } - Serial.println(command); + char command[8]; + char currentChar; + int i = 0; + bool readable = true; + while (readable) { + currentChar = Serial.read(); + readable = (currentChar != -1); + if (readable) { + command[i] = currentChar; + i++; + } + } + command[i] = '\0'; + + if (strcmp(command, "LED_on") == 0) { + digitalWrite(ledPin, HIGH); + } + else { + digitalWrite(ledPin, LOW); + } + Serial.println(command); } }