Go Down

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

hotcarrier

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(){
  beginSerial(19200);
}

 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);
      //Serial.println(luckyNumber);
   }


imagitronics

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.
Tim

Go Up