Završni rad Androić H most upravljan MBED-om

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
cvitas
Date:
Tue May 12 19:50:52 2015 +0000
Parent:
1:a09621d44b14
Commit message:
potenciometar upravlja DC motorom

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r a09621d44b14 -r 9500cf2f8f8b main.cpp
--- a/main.cpp	Tue May 12 19:31:21 2015 +0000
+++ b/main.cpp	Tue May 12 19:50:52 2015 +0000
@@ -1,7 +1,8 @@
 #include "mbed.h"
 
-//DigitalOut OUT_A(p21);
-//DigitalOut OUT_B(p22);
+AnalogIn Ain(p20);
+float ADCdata;
+
 PwmOut OUT_A(p21);
 PwmOut OUT_B(p22);
 
@@ -10,41 +11,19 @@
     
       OUT_A.period(0.010);              // set PWM period to 10 ms  
       while(1) {
-      
-      OUT_A=0.0;                // set duty cycle to 0%
-      for(float p = 0.0f; p < 1.0f; p += 0.05f) {
-            OUT_B= p;
-            wait(0.1);
-            }
-      wait(2);
-      OUT_B=0.0;                // set duty cycle to 0%
-      OUT_A=0.0;                // set duty cycle to 0%
-      wait(0.5);
-      OUT_B=0.0;                // set duty cycle to 0%
-      for(float p = 0.0f; p < 1.0f; p += 0.05f) {
-            OUT_A= p;
-            wait(0.1);
-            }
-      wait(2);
-      OUT_B=0.0;                // set duty cycle to 0%
-      OUT_A=0.0;                // set duty cycle to 0%
-      wait(0.5);
+      ADCdata=Ain;
+      if (ADCdata>0.5)
+      {
+        OUT_A=0.0;                // set duty cycle to 0%
+        OUT_B= 2*(ADCdata-0.5);
+      }
+      else
+      {
+        OUT_B=0.0;                // set duty cycle to 0%
+        OUT_A= 2*(-ADCdata+0.5);
+      }      
       
       }
   
-        /*
-        OUT_A = 1;
-        OUT_B = 0;
-        wait(2);
-        OUT_A = 0;
-        OUT_B = 0;
-        wait(1);
-        OUT_A = 0;
-        OUT_B = 1;
-        wait(2);
-        OUT_A = 0;
-        OUT_B = 0;
-        wait(1);*/
-        
-    
+   
 }