lab5

Fork of PwmOut_HelloWorld by mbed_example

Files at this revision

API Documentation at this revision

Comitter:
Asimtaj
Date:
Thu Nov 23 17:03:29 2017 +0000
Parent:
3:10bf740dc758
Commit message:
lab5

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 10bf740dc758 -r ef9385dba098 main.cpp
--- a/main.cpp	Fri Jun 23 17:59:41 2017 -0500
+++ b/main.cpp	Thu Nov 23 17:03:29 2017 +0000
@@ -1,12 +1,50 @@
 #include "mbed.h"
 
-PwmOut led(LED1);
-
+ 
+PwmOut PWM0(p21); //PWM out
+ AnalogIn   ain0(p16); //Analog input A0
+ AnalogIn   ain1(p20); //Analog input A1
+ DigitalOut ledasim(LED1);
+ DigitalOut ledasim2(LED2);
+Serial pc(USBTX, USBRX); // tx, rx
+float test=0;
 int main() {
+    int ain11 = 0;
+    //PWM0.period(0.0f);      // 0second period
+    //PWM0.write(0.0f);
+    test=ain1;
+    pc.printf("%f\n\r",test);
+    wait(5);
+    while(ain1>0.18){
+        test=ain1;
+    pc.printf("%f\n\r",test);
+        }
+    while(1){
+       if(ain1<0.8){ 
     // specify period first
-    led.period(4.0f);      // 4 second period
-    led.write(0.50f);      // 50% duty cycle, relative to period
+    PWM0.period(0.0025f);      // 0.0025 second period
+    PWM0.write(0.8f);      // 50% duty cycle, relative to period
     //led = 0.5f;          // shorthand for led.write()
     //led.pulsewidth(2);   // alternative to led.write, set duty cycle time in seconds
-    while(1);
-}
\ No newline at end of file
+    //printf("ll");
+    ledasim=!ledasim;
+    //printf("%f\n\r",ain0);
+    //printf(" %f\n\r", ain0.read());
+}
+    wait(5);
+    while(1){
+    wait(0.25);
+    test=ain0;
+    pc.printf("%f\n\r",test);
+    if(ain0 > 0.289 || ain0 < 0.268) {
+    PWM0.period(0.0f);      // 0second period
+    PWM0.write(0.0f);
+    ain11= 1;
+      } else if(ain11 == 0){
+    PWM0.period(0.0025f);      // 0second period
+    PWM0.write(0.8f);
+    }
+      }
+    
+  }
+    }
\ No newline at end of file