Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions Language/Functions/Communication/Serial/readString.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,49 @@ title: Serial.readString()
=== Returns
A `String` read from the serial buffer


--
// OVERVIEW SECTION ENDS


// HOW TO USE SECTION STARTS
[#howtouse]
--

[float]
=== Example Code
Demonstrate Serial.readString()

[source,arduino]
----
void setup() {
Serial.begin(9600);
}

void loop() {
Serial.println("Enter data:");
while (Serial.available() == 0) {} //wait for data available
String teststr = Serial.readString(); //read until timeout
teststr.trim(); // remove any \r \n whitespace at the end of the String
if (teststr == "red") {
Serial.println("A primary color");
} else {
Serial.println("Something else");
}
}
----
[%hardbreaks]


[float]
=== Notes and Warnings
The function does not terminate early if the data contains end of line characters. The returned `String` may contain carriage return and/or line feed characters if they were received.
[%hardbreaks]

--
// HOW TO USE SECTION ENDS


// SEE ALSO SECTION
[#see_also]
--
Expand Down