![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
part1
Dependencies: mbed
Diff: main.cpp
- Revision:
- 7:89a6d9004710
- Parent:
- 6:ab02d7bb40cb
- Child:
- 8:8991b0b82440
diff -r ab02d7bb40cb -r 89a6d9004710 main.cpp --- a/main.cpp Tue Feb 17 19:58:06 2015 +0000 +++ b/main.cpp Sun Feb 22 17:53:02 2015 +0000 @@ -7,7 +7,7 @@ Timer t1; -//Initialize Input that is 8 character +//Initialize Input buffer char input[10]; @@ -27,12 +27,14 @@ printf("Input Desired Tone: Frequency (Hz) Duration (ms) followed by enter\r"); char c = pc.getc(); int i =0; + + //wait for return to be pressed while(c != '\r') { - printf("%c",c); - input[i++]=c; + printf("%c",c); //echo + input[i++]=c; //add current char to buffer c = pc.getc(); } - input[i] = '\0'; + input[i] = '\0'; //end buffer //fgets(input, sizeof input, stdin); //input size length 9 followed by enter (xxxx xxxx/r) isint = sscanf(input, "%f %d",&freq,&dur); //assign input variables @@ -43,6 +45,8 @@ } + + //wait for another enter to output the tone if(pc.readable()) { //if enter is pressed continue to output tone if(pc.getc() == '\r') @@ -64,7 +68,8 @@ t1.stop(); } - //if anyother button is pressed abort and start over + + //if another button is pressed besides enter abort and start over else{ printf("You didn't press enter you idiot\r"); isint = 0;