Simon Ford / Mbed 2 deprecated stdout

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 // example showing how to re-route stdout, sford
00002 
00003 #include "mbed.h"
00004 #include "TextLCD.h"
00005 
00006 Serial pc(USBTX, USBRX, "hi");
00007 TextLCD lcd(p10, p11, p12, p15, p16, p29, p30, "lcd"); // rs, rw, e, d0-d3, name
00008 LocalFileSystem local("local");
00009 
00010 int main() {
00011     // printf to specific peripherals
00012     pc.printf("Hello World!\n");
00013     lcd.printf("Hello World!\n");
00014 
00015     // printf to stdout
00016     printf("Hello USB Serial World!\n");
00017     
00018     // change stdout to file
00019     freopen("/local/output.txt", "w", stdout);
00020     printf("Hello FileSystem World!\n");
00021     fclose(stdout);
00022     
00023     // change stdout to LCD
00024     freopen("/lcd", "w", stdout);
00025     printf("Hello LCD World!\n");
00026     fclose(stdout);
00027 
00028     wait(5);    
00029 
00030     pc.printf("Hello World!\n");
00031     lcd.printf("Hello World!\n");
00032 }