Honmaka Astro MicroControler sample PluseMotor Sample Ver 2

Dependencies:   mbed

Fork of PulseMotor by Honmaka Astro

Revision:
1:c533a17dccc0
Parent:
0:27fe3b05f1fc
--- a/main.cpp	Sun Jan 04 07:55:14 2015 +0000
+++ b/main.cpp	Sat Jan 10 06:25:14 2015 +0000
@@ -1,10 +1,24 @@
 #include "mbed.h"
 
 PwmOut PulseMotor(p21);
+DigitalIn   MotorSpeedSw(p5);
+DigitalIn   MotorDirectionSw(p6);
+DigitalOut  MotorDirectionOut(p7);
 
 int main() {
-    PulseMotor.period_us(83140);
-    PulseMotor.pulsewidth_us(83140/2); 
+    MotorSpeedSw.mode(PullUp);
+    MotorDirectionSw.mode(PullUp);
+    //Dorection
+    MotorDirectionOut = MotorDirectionSw;
+    //Speed
+    if (MotorSpeedSw == 1) { //Normal Speed
+        PulseMotor.period_us(83140);
+        PulseMotor.pulsewidth_us(83140/2);
+    }
+    else {                     //Half Speed
+        PulseMotor.period_us(83140*2);
+        PulseMotor.pulsewidth_us((83140*2)/2);
+    } 
     while(1) {
     }
 }