From 360e7338b8ec64e90e8fdc66510ab5a49bd82235 Mon Sep 17 00:00:00 2001 From: Petr Baudis Date: Wed, 28 Dec 2011 06:42:48 +0100 Subject: [PATCH] Sketch: Clean up the reading loop slightly --- sketch/lasic.pde | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/sketch/lasic.pde b/sketch/lasic.pde index 4f61e06..c14fd36 100644 --- a/sketch/lasic.pde +++ b/sketch/lasic.pde @@ -44,26 +44,25 @@ void loop() { while(Serial.available()) { lastTime = millis(); InByte = Serial.read(); - if (InCmdIndex >= sizeof(InCmd)){ - InCmdIndex = 0; - Serial.println("INPUT COMMAND OVERFLOW"); - } if (InByte == 10 || InByte == 13 ) { //Serial.println(sizeof(InCmd),DEC); + InCmd[InCmdIndex] = 0; ExeCmd(InCmd); - for (InCmdIndex++; InCmdIndex>0; InCmdIndex--) { + for (; InCmdIndex>0; InCmdIndex--) { InCmd[InCmdIndex] = 0; } InCmdIndex = 0; - } else{ InCmd[InCmdIndex++] = InByte; + if (InCmdIndex >= sizeof(InCmd)){ + InCmdIndex = 0; + Serial.println("INPUT COMMAND OVERFLOW"); + } }// Serial.println(InCmdIndex, DEC); } - if ( (lastTime + 15000) < millis() ) { digitalWrite(LaserPIN, LOW); digitalWrite(2, LOW);