Motor2

Dependents:   OneCircleRobot

Fork of Motor by Kiko Ishimoto

Revision:
0:1252cd3b995f
Child:
1:4ab6e9768847
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Motor.cpp	Fri Jun 19 06:35:46 2015 +0000
@@ -0,0 +1,33 @@
+/**
+ * Includes
+ */
+#include "Motor.h"
+
+Motor::Motor(PinName _pin_h1, PinName _pin_g2, PinName _pin_g1, PinName _pin_h2,PinName _pwm,float Max) :
+motor(_pin_h1,_pin_g2,_pin_g1,_pin_h2),PwmPin(_pwm)
+{
+    max=Max;
+    PwmPin.period_ms(10);
+    run(Stop,1);
+}
+void Motor::run(int i,float duty)
+{
+    static int state;
+    Duty = duty/max;
+    //if(state==i)return;
+    PwmPin = Duty;
+    if(state==i)return;
+    Timer t;
+    motor=0;
+    //wait_us(20);
+    t.start();
+    t.reset();
+    while(t.read_us()>=20);
+    if(i==Front) motor=0x01|0x04;
+    else if(i==Back) motor=0x02|0x08;
+    else if(i==Stop) motor=0x01|0x08;
+    else if(i==Free) motor=0x00|0x00;
+    else motor=0;   
+    state=i;
+}
+