Mohammad Mohammad
/
serial_buff
serial comm example
Revision 2:bd1893295536, committed 2014-02-02
- Comitter:
- oliverfang
- Date:
- Sun Feb 02 02:08:24 2014 +0000
- Parent:
- 1:dd2f972ef479
- Commit message:
- reading in every character
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r dd2f972ef479 -r bd1893295536 main.cpp --- a/main.cpp Sat Feb 01 23:58:09 2014 +0000 +++ b/main.cpp Sun Feb 02 02:08:24 2014 +0000 @@ -1,13 +1,13 @@ #include "mbed.h" #include "PinDetect.h" -// Hi Mohammed, I am testing the commit system - DigitalOut myled(PTD5); DigitalOut myled1(PTE29); //DigitalIn enable(PTC3); //InterruptIn button(PTC3); +//construct an object called button that represents one of the pins +//constructor requires a pin name: PTC3 in this case PinDetect button(PTC3); Serial pc(USBTX,USBRX); @@ -23,13 +23,26 @@ myled1 = 0; button.mode(PullUp); wait(.001); + // interrupt button.attach_deasserted(&flip); button.setSampleFrequency(); char buffer[128]; - while(1) { - pc.gets(buffer,4); - pc.printf("i got '%s'\r\n",buffer); + while(1) + { + // read in every character + pc.gets(buffer, 2); + // check if carriage return is pressed + if((int)buffer[0] == 13) + { + // print return and new line + pc.puts("\r\n"); + } + else + { + // otherwise just print the character that was typed + pc.puts(buffer); + } } }