Simple training demonstration to show the use of union and structure
Fork of OddExample2 by
main.cpp@2:db81cad8cb64, 2013-11-25 (annotated)
- Committer:
- jf1452
- Date:
- Mon Nov 25 15:09:03 2013 +0000
- Revision:
- 2:db81cad8cb64
- Parent:
- 1:d9da28105bef
- Child:
- 3:0f80147842c2
Hal is a simple USB Serial demonstrator
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jf1452 | 1:d9da28105bef | 1 | /******************************************************************************* |
jf1452 | 2:db81cad8cb64 | 2 | * This program demonstrates how to read a string from the USB serial device * |
jf1452 | 2:db81cad8cb64 | 3 | * and write a string back to the USB serial device * |
jf1452 | 1:d9da28105bef | 4 | * * |
jf1452 | 1:d9da28105bef | 5 | * Jon Fuge * |
jf1452 | 2:db81cad8cb64 | 6 | * V1.0 25/11/2013 First issue of code * |
jf1452 | 1:d9da28105bef | 7 | *******************************************************************************/ |
dan | 0:7dec7e9ac085 | 8 | |
jf1452 | 2:db81cad8cb64 | 9 | #include "mbed.h" |
jf1452 | 2:db81cad8cb64 | 10 | #include "USBSerial.h" |
jf1452 | 2:db81cad8cb64 | 11 | |
jf1452 | 2:db81cad8cb64 | 12 | //Virtual serial port over USB. Use Teraterm as the interface |
jf1452 | 2:db81cad8cb64 | 13 | USBSerial serial; |
dan | 0:7dec7e9ac085 | 14 | |
dan | 0:7dec7e9ac085 | 15 | int main() { |
jf1452 | 2:db81cad8cb64 | 16 | char buf[128]; // A char array is also a string! |
jf1452 | 2:db81cad8cb64 | 17 | wait (10); // Wait 10 seconds to connect port |
jf1452 | 2:db81cad8cb64 | 18 | // Need to type a key, then enter to get a response. |
jf1452 | 2:db81cad8cb64 | 19 | serial.printf("What is your name?\n\r"); |
jf1452 | 2:db81cad8cb64 | 20 | serial.scanf("%s", buf); |
jf1452 | 2:db81cad8cb64 | 21 | serial.printf("What are you doing %s?\n\r", buf); |
jf1452 | 2:db81cad8cb64 | 22 | for(;;) {} // Loop forever |
jf1452 | 2:db81cad8cb64 | 23 | } |