直流モータ2個を,2つのアナログ入力でデューティ制御するプログラムです。

Dependencies:   Motor mbed

Files at this revision

API Documentation at this revision

Comitter:
Yoshichan
Date:
Sun Aug 03 16:37:46 2014 +0000
Commit message:
Two DC motors can be driven by using two Analog inputs.

Changed in this revision

Motor.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
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r c4b58f8a436e Motor.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Motor.lib	Sun Aug 03 16:37:46 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/simon/code/Motor/#f265e441bcd9
diff -r 000000000000 -r c4b58f8a436e main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sun Aug 03 16:37:46 2014 +0000
@@ -0,0 +1,46 @@
+// Sweep the motor speed from full-speed reverse (-1.0) to full speed forwards (1.0)
+
+#include "mbed.h"
+#include "Motor.h"
+
+Motor m1(p23, p6, p5);   // pwm, fwd, rev
+AnalogIn ain1(p16);// AD input for Motor1
+
+Motor m2(p22, p8, p7);   // pwm, fwd, rev
+AnalogIn ain2(p15);// AD input for Motor2
+
+int main() {
+    while(1)
+    {
+        float k1=(ain1-0.5)*1.2;
+        if(k1>0.6)
+        {
+            k1=0.6;
+        }
+        else
+        {
+            if(k1<-0.6)
+            {
+                k1=-0.6;
+            }
+            else{}
+        }
+        
+        float k2=(ain2-0.5)*1.2;
+        if(k2>0.6)
+        {
+            k2=0.6;
+        }
+        else
+        {
+            if(k2<-0.6)
+            {
+                k2=-0.6;
+            }
+            else{}
+        }        
+        m1.speed(k1); 
+        m2.speed(k2); 
+        wait(0.1);
+    }
+}
diff -r 000000000000 -r c4b58f8a436e mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Sun Aug 03 16:37:46 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/e2ac27c8e93e