8 years, 7 months ago.

How to pc.print a variable's value in Tera Term software tools on display???

/*What is the function to pc.printf() various input parameters show???I'm a beginner */

  1. include "mbed.h"

DigitalOut myled(LED2); Serial pc(USBTX,USBRX); int main() { while(1) { unsigned i; myled = 0; pc.printf("hello world ");This can be printed on the terminal with Tera Term software tools(hello world)

/* I want to print on the terminal output variable (I) value but it doesnot work. */ /* for(i = 0; i < 10; i++) { printf("%d\n", i ); }

  • /

wait(1); myled = 1; wait(1); } }

How to use the function of the pc.printf () to print out the value of a variable?Does anyone know? I will thank you very much for your help

1 Answer

8 years, 7 months ago.

<<CODE>>
DigitalOut myled(LED2); 
Serial pc(USBTX,USBRX); 
int main()
 { 
while(1) 
{ 
 unsigned i;  
 myled = 0; 
 pc.printf("hello world ");
  for(i = 0; i < 10; i++) 
 pc.printf("%d\n", i );     <-- use pc before printf to display it through terraterm !
 ....

 wait(1); 
 myled = 1; 
 wait(1); 
 } 
}
<</CODE>>

and please use "<<code>> your code <</code>>" to make sources more readable...

Accepted Answer

one minor detail: Since i is an unsigned int the printf should be %u not %d. For small numbers it won't make any difference but for large numbers (over about 2 billion on a 32 bit system) it will.

posted by Andy A 11 Sep 2015