lab2_4

Dependencies:   mbed 2_4_PWM_Ouput

Dependents:   2_4_PWM_Ouput

Revision:
1:4340a1ec8b5c
Parent:
0:543a9d21e043
--- a/main.cpp	Sun Feb 26 08:47:54 2017 +0000
+++ b/main.cpp	Wed Mar 01 10:09:34 2017 +0000
@@ -1,7 +1,25 @@
 #include "mbed.h"
 PwmOut PWM1(D6);
-
+Serial pc( USBTX, USBRX );
+AnalogIn Ain(A0);
+float ADCdata;
 int main() {
-    PWM1.period(0.01);
+    int on = 0;
+    int off = 0;
+    float Cycle = 0.0;
+    PWM1.period(0.5);
     PWM1 = 0.5;
+    while(1){
+        ADCdata = Ain;
+        if(ADCdata > 0.5){
+            on = on + 1;    
+        }
+        else{
+            off = off + 1.0;   
+        }
+        Cycle = float(on)/(float(off)+float(on));
+        pc.printf("%f\r\n", Cycle);
+        //pc.printf("%1.3f\r\n", off);
+        wait(0.1);
+    }
 }
\ No newline at end of file