part1
Dependencies: mbed
Diff: main.cpp
- Revision:
- 2:255d7e71c69b
- Parent:
- 1:93eb2c653c86
- Child:
- 3:664e38d7ae34
diff -r 93eb2c653c86 -r 255d7e71c69b main.cpp --- a/main.cpp Thu Feb 12 21:11:49 2015 +0000 +++ b/main.cpp Fri Feb 13 17:57:57 2015 +0000 @@ -1,5 +1,5 @@ #include "mbed.h" - +//Right now this is only working for inputs length 3 //Initialize PWM PwmOut PWM1(p21); @@ -8,13 +8,15 @@ //Initialize Input that is 8 character -char input[8]; +char input[10]; int main() { + //define input variables float freq; int dur; + //Check if input is valid int isint; while(1){ @@ -23,21 +25,25 @@ { //Input Desired Tone printf("Input Desired Tone: Frequency (Hz) Duration (ms) followed by enter\r"); - fgets(input, sizeof input, stdin); - isint = sscanf(input, "%3f %3d",&freq,&dur); - printf("isint = %d\r",isint); + 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 + printf("isint = %d\r",isint); //debug check if input is correct + //if input is incorrect this will be displayed if(isint!= 2) printf("You did not enter a number.Please enter an argument's number\r"); } if(pc.readable()) { - //if enter is pressed continue + //if enter is pressed continue to output tone if(pc.getc() == '\r') { + //show user what value was input printf("Valid Input Frequency = %3.0f, Duration = %d\r", freq, dur); isint = 0; //reset input + //Play tone with correct freq and durration + //Timer used for duration t1.reset(); t1.start(); PWM1.period(1/freq); // set PWM period to 10 ms