Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add example and notes and warnings sections #808

Merged
merged 4 commits into from
Aug 16, 2022
Merged
Changes from 1 commit
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
grayconstruct marked this conversation as resolved.
Show resolved Hide resolved
String teststr = Serial.readString(); //read until timeout
teststr.trim(); // remove any \r \n whitespace at the end of the String
if(teststr=="red") {
grayconstruct marked this conversation as resolved.
Show resolved Hide resolved
Serial.println("A primary color");
} else {
Serial.println("Something else");
}
}
----
[%hardbreaks]


[float]
=== Notes and Warnings
The function does not terminate early because of end of line characters and the returned String may contain carriage return and/or line feed characters if they were received.
grayconstruct marked this conversation as resolved.
Show resolved Hide resolved
[%hardbreaks]

--
// HOW TO USE SECTION ENDS


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