Skip to content

Add an example code to abs() [CNT-1196] #841

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

Merged
merged 3 commits into from
Nov 2, 2021
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
27 changes: 27 additions & 0 deletions Language/Functions/Math/abs.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,34 @@ Calculates the absolute value of a number.
// HOW TO USE SECTION STARTS
[#howtouse]
--
[float]
=== Example Code
// Describe what the example code is all about and add relevant code ►►►►► THIS SECTION IS MANDATORY ◄◄◄◄◄
Prints the absolute value of variable `x` to the Serial Monitor.

[source,arduino]
----
void setup() {
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
int x = 42;
Serial.print("The absolute value of ");
Serial.print(x);
Serial.print(" is ");
Serial.println(abs(x));
x = -42;
Serial.print("The absolute value of ");
Serial.print(x);
Serial.print(" is ");
Serial.println(abs(x));
}

void loop() {
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mkaivo maybe we can add a delay in the end.

----
[%hardbreaks]

[float]
=== Notes and Warnings
Expand Down