lab2_4

Dependencies:   mbed 2_4_PWM_Ouput

Dependents:   2_4_PWM_Ouput

Files at this revision

API Documentation at this revision

Comitter:
shih775007
Date:
Wed Mar 01 10:09:34 2017 +0000
Parent:
0:543a9d21e043
Commit message:
quiz1_2

Changed in this revision

2_4_PWM_Ouput.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 543a9d21e043 -r 4340a1ec8b5c 2_4_PWM_Ouput.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/2_4_PWM_Ouput.lib	Wed Mar 01 10:09:34 2017 +0000
@@ -0,0 +1,1 @@
+https://developer.mbed.org/users/shih775007/code/2_4_PWM_Ouput/#543a9d21e043
diff -r 543a9d21e043 -r 4340a1ec8b5c main.cpp
--- 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