Skip to content

Instantly share code, notes, and snippets.

@DefProc
Created May 31, 2017 08:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DefProc/07cc59cbe8c94c7fb6a6a757ad34bc1f to your computer and use it in GitHub Desktop.
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
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