Motor2

Dependents:   OneCircleRobot

Fork of Motor by Kiko Ishimoto

Revision:
3:dea2df71cb97
Parent:
2:ef4a9c047681
Child:
4:56a1159c881c
--- a/Motor.cpp	Tue Aug 18 04:44:54 2015 +0000
+++ b/Motor.cpp	Wed Sep 23 06:01:10 2015 +0000
@@ -2,28 +2,36 @@
  * Includes
  */
 #include "Motor.h"
+Motor::Motor(const Motor& m):
+    motor(m.Pin[0],m.Pin[1],m.Pin[2],m.Pin[3]),PwmPin(m.Pin[4])
+{
+    max=m.max;
+    //this
+    PwmPin.period_ms(20);
+    run(Stop,1);
+}
 
-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)
+Motor::Motor(PinName _pin_h1, PinName _pin_g2, PinName _pin_g1, PinName _pin_h2,PinName _pwm) :
+    motor(_pin_h1,_pin_g2,_pin_g1,_pin_h2),PwmPin(_pwm)
 {
-    max=Max;
-    //this 
+     Pin[0] = _pin_h1;
+    Pin[1] = _pin_g2;
+    Pin[2] = _pin_g1;
+    Pin[3] = _pin_h2;
+    Pin[4] = _pwm;
+    max=1.0;
+    //this
     PwmPin.period_ms(10);
     run(Stop,1);
 }
-void Motor::setup(int _state)
-{
-    
-}
 void Motor::run(int i,float duty)
 {
-    static int state;
-    Duty = (float)duty;
+    //static int state;
+    Duty = (float)duty*max;
     //printf("Duty %f \n",(float)duty);
     //if(state==i)return;
-    PwmPin = Duty;
+    PwmPin = Duty*Duty;
     if(state==i)return;
-    Timer t;
     motor=0;
     //wait_us(20);
     /*t.start();
@@ -34,9 +42,10 @@
     else if(i==Back) motor=0x02|0x08;
     else if(i==Stop) motor=0x01|0x08;
     else if(i==Free) motor=0x00|0x00;
-    else motor=0;   
+    else motor=0;
     state=i;
 }
 
 
 
+