3 years, 2 months ago.

Can not use "scanf" to get input from host PC keyboard via USB communication?

Hi there,

I am using LPC4088 to get my keyboard input via USB serial communication from the host PC ? The commands (putc , getc, and printf) are working. However, scanf does not work. It displayed nothing after typing several numbers on the keyboard. The code is:

Serial pc(USBTX, USBRX); tx, rx

int main() { float input; pc.baud(115200);

while(1) {

pc.printf("Please type a value:\n"); pc.scanf("%f", input); pc.printf("The input value is: %f\n", input);

} }

1 Answer

3 years, 2 months ago.

1) to make code readable please use

<<code>>
your code
<</code>>

2) you are using scanf incorrectly, it takes a pointer to the variable, not the variable. Try

Serial pc(USBTX, USBRX); //tx, rx

int main() {
 float input; 
 pc.baud(115200);

 while(1) {
   pc.printf("Please type a value:\n");
   pc.scanf("%f", &input);  // & to pass a pointer to input
   pc.printf("The input value is: %f\n", input);
 }
}