part1

Dependencies:   mbed

Revision:
1:93eb2c653c86
Parent:
0:2c98a4766d9f
Child:
2:255d7e71c69b
--- a/main.cpp	Tue Feb 10 20:37:52 2015 +0000
+++ b/main.cpp	Thu Feb 12 21:11:49 2015 +0000
@@ -1,46 +1,60 @@
 #include "mbed.h"
-#include "string.h"
-#include <string>
+
 
 //Initialize PWM
 PwmOut PWM1(p21);
 Serial pc(USBTX, USBRX);
-
-//Initialize variables that will be used to read
-std::string input; 
+Timer t1;
 
 
-int main()
+//Initialize Input that is 8 character
+char input[8];
+
+  
+ int main()
 {
+    float freq;
+    int dur;
+    int isint;
     while(1){
-        if(pc.readable()) {
-            char c = pc.getc(); 
-            x = strlen(input);
-            //If enter is pressed process input
-            if(c  == '\r'){
-                //check to see if valid input
-                if(sizeof(input) == 7){
-                    pc.printf("%s",input);                        //print input for debugging
-                    input.clear();                                //clear input
+         
+            //wait for a valid input
+            while(isint != 2) 
+            {
+                //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);
+                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(pc.getc() == '\r')
+             {
+                printf("Valid Input Frequency = %3.0f, Duration  = %d\r", freq, dur);
+                isint = 0;  //reset input
+                
+                t1.reset();
+                t1.start();
+                PWM1.period(1/freq);               // set PWM period to 10 ms   
+                PWM1=0.5;                         // set duty cycle to 50% 
+                while(t1.read_ms() < dur){
+                    //WAIT
                     }
-                //mark as invalid input clear data
-                else{
-                    input.clear();                                 //clear input
-                    pc.printf("Invalid Input /n");                 //print space
-                    }                
-                }
-            //Else add the character to current input
-            else{
-            // add character to current input string
-            input = input + c;
-            pc.printf("%s\n",input);                        //print input for debugging
-            pc.printf("%d",sizeof(input));
-            } 
-            wait(0.1);
-        }
-        
-        
-        
-    }
-}
- 
\ No newline at end of file
+                PWM1=0.0;                         //turn off
+                t1.stop();
+                
+             }
+            //if anyother button is pressed abort and start over
+             else{
+                printf("You didn't press enter you idiot\r");
+                isint = 0;  
+                 }
+            }    
+      }
+      
+}
\ No newline at end of file