Created
May 31, 2017 08:31
-
-
Save DefProc/07cc59cbe8c94c7fb6a6a757ad34bc1f to your computer and use it in GitHub Desktop.
Pass a second argument to print() or println() to set the number of decimal places in Arduino Serial library
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
float aNumber = 999; | |
void setup() { | |
Serial.begin(115200); | |
} | |
void loop() { | |
/* TIL: | |
* the second argument in print is the number of decimal | |
* places printed when passed a float/double | |
*/ | |
Serial.println(aNumber, 6); | |
aNumber = aNumber / 2.0f; | |
if (aNumber < 0.0000005f) { | |
Serial.println(F("fin.")); | |
pinMode(LED_BUILTIN, OUTPUT); | |
while (1) { | |
// indicate finished | |
digitalWrite(LED_BUILTIN, HIGH); | |
delay(500); | |
digitalWrite(LED_BUILTIN, LOW); | |
delay(500); | |
} | |
} | |
delay(1000); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment