Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: main.cpp
- Revision:
- 4:dfb672184380
- Parent:
- 3:7188bd978801
- Child:
- 5:03b7c237c4c4
--- a/main.cpp Mon Apr 14 00:33:00 2014 +0000 +++ b/main.cpp Mon Apr 14 00:45:29 2014 +0000 @@ -8,23 +8,35 @@ void sendText(char *thisText) { + // this can send any text usbSerial.printf(thisText); } //----------------------------------------------------------------------------- void sendHelloWorld() { + // sends the first greeting sendText("** Hello World **\n\n> "); } //----------------------------------------------------------------------------- void scanUSBSerialRx() { + // check if there is something to read if(usbSerial.readable()) { + + // if so ... char character = usbSerial.getc(); - if((character == ';') || (character == 13)) usbSerial.printf("\n> "); + + // see if this is a semi colon or a carriage return + // if so, give a new line cursor + if((character == ';') || (charac ter == 13)) usbSerial.printf("\n> "); + + // if not, just print the character else usbSerial.printf("%c", character); } + + // reset the flag scanUSBSerialRxFlag = false; } //----------------------------------------------------------------------------- @@ -37,10 +49,13 @@ void initMain() { + // increase the baud rate for the USB serial port usbSerial.baud(115200); + // send greeting with first cursor sendHelloWorld(); + // start polling for characters scanTicker.attach(&setScanUSBSerialRxFlag, 0.01); scanUSBSerialRxFlag = false; } @@ -49,8 +64,12 @@ int main() { initMain(); - while(true) { + while(true) { + + // check the flag if(scanUSBSerialRxFlag) scanUSBSerialRx(); + + // give the main loop some time wait(0.02); } }