Ovo je kopija vertije od Milana

Dependencies:   TextLCD mbed

Fork of SunflowerMach1 by Milan Draganic

Revision:
3:bebfc64cefe4
Parent:
1:3500bf8487d0
Child:
4:03b68322905f
diff -r 0bf41ad96558 -r bebfc64cefe4 MotorDrivers/Motor.cpp
--- a/MotorDrivers/Motor.cpp	Sat Nov 09 07:04:13 2013 +0000
+++ b/MotorDrivers/Motor.cpp	Sat Nov 09 13:44:18 2013 +0000
@@ -1,10 +1,15 @@
 #include "Motor.h"
 
-Motor::Motor() : positiveOut(NC), negativeOut(NC) {
-}
-
-Motor::Motor(PinName positivePin, PinName negativePin): 
-        positiveOut(positivePin), negativeOut(negativePin) {
+Motor::Motor(PinName positivePin, PinName negativePin, PinName pwmPin): 
+        positiveOut(positivePin), negativeOut(negativePin), pwmOut(pwmPin) {
+        
+    pwmOut.period(motorPwmPeriod);
+    pwmOut = motorPwmInitDutyCycle;
+    
+    positiveOut = 0;
+    negativeOut = 0;   
+    
+    _isMoving = false;
 }
 
 void Motor::movePositive() {
@@ -35,13 +40,32 @@
         break;
     }
     
-    direction = 0;
-    wait_ms(motorDriveTime);
+    for (float i = 1; i > 0; i -= motorPwmChangeSpeed) {
+        pwmOut = i;
+        wait(motorPwmWaitTime);
+    }        
+    pwmOut = 0;
+    _isMoving = true;
+    
+//    wait_ms(motorDriveTime);
+//    stop();
 }
 
 void Motor::stop() {
 
+    for (float i = 0; i < 1; i += motorPwmChangeSpeed) {
+        pwmOut = i;
+        wait(motorPwmWaitTime);
+    }
+    pwmOut = 1;
+
     positiveOut = 0;
     negativeOut = 0;
     direction = 0;
+    _isMoving = false;
 }
+
+bool Motor::isMoving() {
+
+    return _isMoving;
+}