// we need fundamental FILE definitions and printf declarations #include // create a FILE structure to reference our UART output function static FILE uartout = {0} ; // create a output function // This works because Serial.write, although of // type virtual, already exists. static int uart_putchar (char c, FILE *stream) { Serial.write(c) ; return 0 ; } void setup(void) { // Start the UART Serial.begin(9600) ; // fill in the UART file descriptor with pointer to writer. fdev_setup_stream (&uartout, uart_putchar, NULL, _FDEV_SETUP_WRITE); // The uart is the standard output device STDOUT. stdout = &uartout ; } void loop(void) { float seconds ; // wait 1000 milliseconds delay(1000) ; // calculate seconds as a floating point value seconds = (float) millis() /1000.0 ; // report seconds since starting printf("Alive %.3f sec", seconds ) ; /* // without printf(), you would do this: Serial.print("Alive ") ; Serial.print(seconds,3) ; Serial.print("sec") ; */ #if 0 // you can explicitly use a FILE structure like this: fprintf( &uartout, "Alive %.3f sec", seconds ) ; #endif }