From 0e3ec2d5033eb462f3feae09d3b83a6fe7958626 Mon Sep 17 00:00:00 2001 From: Melissa <54317642+mkaivo@users.noreply.github.com> Date: Fri, 16 Jul 2021 15:55:06 +0200 Subject: [PATCH 1/3] Add an example code to abs() CNT-1196 Hi, we got a request to add an example code of abs(). Could this work? It is a pretty straightforward function. See the Jira task here: https://arduino.atlassian.net/browse/CNT-1196 --- Language/Functions/Math/abs.adoc | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/Language/Functions/Math/abs.adoc b/Language/Functions/Math/abs.adoc index c24610f7a..d5a8685a1 100644 --- a/Language/Functions/Math/abs.adoc +++ b/Language/Functions/Math/abs.adoc @@ -45,7 +45,27 @@ 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 a to the Serial Monitor. +[source,arduino] +---- +int a = 5; +float absolute = 0.0; + +void setup() { + Serial.begin(9600); +} + +void loop() { + a++; //Adds one to the variable a + absolute = abs(a); //Stores the absolute value of the variable a to the variable absolute + Serial.println(absolute); //Prints to the Serial Monitor the value of the variable absolute +} +---- +[%hardbreaks] [float] === Notes and Warnings From dc33cba5b8af69b79395c3774f1bd59e59849044 Mon Sep 17 00:00:00 2001 From: Melissa <54317642+mkaivo@users.noreply.github.com> Date: Fri, 13 Aug 2021 15:49:57 +0200 Subject: [PATCH 2/3] Update abs.adoc --- Language/Functions/Math/abs.adoc | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/Language/Functions/Math/abs.adoc b/Language/Functions/Math/abs.adoc index d5a8685a1..eff19af13 100644 --- a/Language/Functions/Math/abs.adoc +++ b/Language/Functions/Math/abs.adoc @@ -52,17 +52,24 @@ Prints the absolute value of variable a to the Serial Monitor. [source,arduino] ---- -int a = 5; -float absolute = 0.0; - void setup() { - Serial.begin(9600); + 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() { - a++; //Adds one to the variable a - absolute = abs(a); //Stores the absolute value of the variable a to the variable absolute - Serial.println(absolute); //Prints to the Serial Monitor the value of the variable absolute } ---- [%hardbreaks] From 30daf96fa96894fed1088a5cd0458ac83a860123 Mon Sep 17 00:00:00 2001 From: Melissa <54317642+mkaivo@users.noreply.github.com> Date: Fri, 24 Sep 2021 14:08:12 +0200 Subject: [PATCH 3/3] Update Language/Functions/Math/abs.adoc Co-authored-by: per1234 --- Language/Functions/Math/abs.adoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Language/Functions/Math/abs.adoc b/Language/Functions/Math/abs.adoc index eff19af13..d494e4c1f 100644 --- a/Language/Functions/Math/abs.adoc +++ b/Language/Functions/Math/abs.adoc @@ -48,7 +48,7 @@ Calculates the absolute value of a number. [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 a to the Serial Monitor. +Prints the absolute value of variable `x` to the Serial Monitor. [source,arduino] ----