Skip to content

Instantly share code, notes, and snippets.

@massenz
Created June 14, 2016 05:43
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 massenz/c38c34d6585bccc9d4104414b8a058a9 to your computer and use it in GitHub Desktop.
Save massenz/c38c34d6585bccc9d4104414b8a058a9 to your computer and use it in GitHub Desktop.
Platformio fail to printf() floats
// AlertAvert.com (c) 2016. All rights reserved
//
// The code below has been adapted from tutorials on
// mbed.org - credits should go to ARM Ltd.
//
// Author: M. Massenzio
#include "mbed.h"
// USB out to the host PC - from a terminal window access
// using: screen /dev/ttyACM0 (use Ctrl-A Ctrl-K to kill).
//
// On OS X, to find the dev do:
// ls /dev/tty.usbmodem*
//
Serial pc(USBTX, USBRX); // tx, rx
// Board LEDs
DigitalOut myled(LED1);
DigitalOut yourled(LED2);
bool on = true;
void quit() {
on = false;
}
void toggle(DigitalOut d1, DigitalOut d2) {
d1 = !d1;
d2 = !d2;
}
int main() {
float intvl = 0.2f;
pc.printf("Starting LED flashing every %.3f sec\r\n", intvl);
Timeout to;
myled = !(yourled = 1);
to.attach(&quit, 5);
while(on) {
toggle(myled, yourled);
wait(0.2);
}
myled = yourled = 0;
pc.printf("Exiting now - %.3f; %d; %f\r\n", 3.14159, 99, 2.768);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment