Created
June 7, 2018 08:40
-
-
Save mahenzon/f8b7e93dba716c861aa886afe5a6f9c5 to your computer and use it in GitHub Desktop.
Read Arduino serial port and print the line
This file contains 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 characters
String readString; | |
int state = LOW; | |
void setup() { | |
Serial.begin(9600); | |
pinMode(LED_BUILTIN, OUTPUT); | |
Serial.println("Starting"); | |
} | |
void loop() { | |
while (Serial.available()) { | |
if (state == LOW) { | |
state = HIGH; | |
digitalWrite(LED_BUILTIN, HIGH); | |
} | |
delay(2); // wait to allow buffer to fill | |
if (Serial.available() > 0) { | |
char c = Serial.read(); // gets one byte from serial buffer | |
readString += c; // makes the str readString | |
} | |
} | |
if (readString.length() > 0) { | |
Serial.println(readString); // see what was received | |
readString=""; | |
if (state == HIGH) { | |
state = LOW; | |
digitalWrite(LED_BUILTIN, LOW); | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment