Simple training demonstration to show the use of union and structure
Fork of OddExample2 by
Diff: main.cpp
- Revision:
- 2:db81cad8cb64
- Parent:
- 1:d9da28105bef
- Child:
- 3:0f80147842c2
diff -r d9da28105bef -r db81cad8cb64 main.cpp --- a/main.cpp Mon Nov 25 14:26:04 2013 +0000 +++ b/main.cpp Mon Nov 25 15:09:03 2013 +0000 @@ -1,24 +1,23 @@ /******************************************************************************* -* This program demonstrates how to read a switch and toggle a LED. * -* Connect LED and resistor between to DIP36 (P0_21) and DIP1 (0V). * -* Connect switch between DIP5 (P0_9) and DIP1 (0V). * +* This program demonstrates how to read a string from the USB serial device * +* and write a string back to the USB serial device * * * * Jon Fuge * -* V1.0 12/11/2013 First issue of code * +* V1.0 25/11/2013 First issue of code * *******************************************************************************/ -#include "mbed.h" // has prototypes for DigitalIn and DigitalOut - -DigitalIn mybutton(P0_9); // mybutton reads bit 9 of port 0 (DIP5). -DigitalOut myled(P0_21); // myled controls bit 21 of port 0 (DIP36). +#include "mbed.h" +#include "USBSerial.h" + +//Virtual serial port over USB. Use Teraterm as the interface +USBSerial serial; int main() { - mybutton.mode(PullUp); // Configure pin to be a pull‐up input - for(;;) { //Create infinite loop to keep program running. - if (mybutton == 0) { // if mybutton = 0, then it has been pressed - myled = !myled; // myled will now become !myled (! means NOT). - wait(0.1); // Wait for 0.1 seconds to "debounce" the switch. - while (mybutton == 0) {} // Wait for my button to be released. - } // End of if (mybutton == 0) - } // End of for(;;) -} // end of int main() \ No newline at end of file + char buf[128]; // A char array is also a string! + wait (10); // Wait 10 seconds to connect port + // Need to type a key, then enter to get a response. + serial.printf("What is your name?\n\r"); + serial.scanf("%s", buf); + serial.printf("What are you doing %s?\n\r", buf); + for(;;) {} // Loop forever +}