Pages: [1]   Go Down
Author Topic: printf  (Read 5228 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 38
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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);
    }

Logged

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 53
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Pages: [1]   Go Up
Jump to: