Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
Hi all,
I've found if I use the default printf() statement to print to the debug console (USB serial) in a program with AnalogIn it causes a runtime error:
Here's the code: (based on a handbook example http://mbed.org/handbook/AnalogIn with printf added)
// Analog input on p20 is displayed as bar chart brightness with on-board LEDs #include "mbed.h" AnalogIn ain(20); DigitalOut led1(LED1); DigitalOut led2(LED2); DigitalOut led3(LED3); DigitalOut led4(LED4); int main() { printf("test\n"); while (1){ led1 = (ain > 0.2) ? 1 : 0; led2 = (ain > 0.4) ? 1 : 0; led3 = (ain > 0.6) ? 1 : 0; led4 = (ain > 0.8) ? 1 : 0; } }If instead I add:
Serial pc(USBTX, USBRX);
Then printf to this Serial it works ok.
pc.printf("LDR test program\n");
Is this a bug or if I've missed the reason by the simple printf should not work? :)
Thanks!
Neil.