Created
December 24, 2015 23:47
-
-
Save RealOrangeOne/ce2ced6f3ecd69e4722b to your computer and use it in GitHub Desktop.
Revisions
-
RealOrangeOne created this gist
Dec 24, 2015 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,42 @@ const char endChar = '\n'; const char commandIdent = '$'; String inputString; boolean hasInput = false; boolean isCommand = false; void setup() { Serial.begin(9600); } void loop() { if (hasInput) { if (isCommand) { Serial.println("Got command: " + inputString); } else { Serial.println("Got input: " + inputString); } inputString = ""; isCommand = false; hasInput = false; } } void serialEvent() { while (Serial.available()) { char inChar = (char)Serial.read(); if (inChar == endChar) { // It's the end of the input stream, let's work out what it is hasInput = true; if (inputString.startsWith(String(commandIdent))) { isCommand = true; inputString.remove(0, 1); } } else { inputString += inChar; } } }