Go Down

Topic: printf (Read 16495 times) previous topic - next topic


Should I expect printf to work? If I include stdio.h programs compile without error but nothing is printed back to the ide.

 #include <stdio.h>
void setup(){

 void loop()
       int luckyNumber = 5;
       float radius = 2;
       char myName[15] = "John";
       char initial = 'J';

       printf("Hello World\n");      
       printf("My lucky number is %d\n", luckyNumber);            
       printf("My name is %s\n",myName);        
       printf("My first initial is %c\n",initial);              
       printf("The area of a circle with radius %f is %f\n",                3.14*radius*radius);


printf doesn't print to the serial port, it just prints to the "display" (of which, there is none on arduino).

If you want the power of printf, try using the sprintf function and then sending the result via Serial.print().

Hope that helps.

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131