Sets motor currents based on input motorvalue

Revision:
2:91ea2963629a
Parent:
1:84cb991c4d28
diff -r 84cb991c4d28 -r 91ea2963629a motorConfig.cpp
--- a/motorConfig.cpp	Sun Oct 22 08:43:06 2017 +0000
+++ b/motorConfig.cpp	Mon Oct 23 13:47:38 2017 +0000
@@ -2,66 +2,35 @@
 #include "mbed.h"
 #include "FastPWM.h"
 
-// Member function definitions
-motorConfig::motorConfig(PinName a, PinName b, PinName c, PinName d, PinName e):ledG(a),ledR(b),ledB(c),directionPin(e),pwmPin(d){
-    currentState = KILLED;
+// Constructor
+motorConfig::motorConfig(PinName _directionPin, PinName _pwmPin):directionPin(_directionPin),pwmPin(_pwmPin){
     pwmPin.period(1.0/5000.0);
     directionPin = 0;
     }
 
+// Other member function definitions
 void motorConfig::setMotor(float motorValue){
-    switch(currentState){
-                case KILLED:
-                    pwmPin.write(0.0);
-                    // Set motor direction
-                    if (motorValue >=0){
-                        // corresponds to CW rotation of motor axle
-                        directionPin = 0;
-                        } else if(motorValue < 0){
-                        // corresponds to CCW rotation of motor axle
-                        directionPin = 1;
-                        }
-                    ledR = 0;
-                    ledG = 1;
-                    ledB = 1;
-                    break;
-                case ACTIVE:
-                    // Set motor direction
-                    if (motorValue >=0){
-                        // corresponds to CW rotation of motor axle
-                        directionPin.write(0);
-                        } else if(motorValue < 0){
-                        // corresponds to CCW rotation of motor axle
-                        directionPin.write(1);
-                        }
+    // Set motor direction
+    if (motorValue >=0){
+        // corresponds to CW rotation of motor axle
+        directionPin.write(0);
+        } else if(motorValue < 0){
+        // corresponds to CCW rotation of motor axle
+        directionPin.write(1);
+        }
                         
-                    // Set motor speed
-                    if (fabs(motorValue)>1){ 
-                        pwmPin = 1.0;
-                        }
-                    else {
-                        pwmPin.write(fabs(motorValue) + 0.4);
-                        }
-                    ledR = 1;
-                    ledG = 1;
-                    ledB = 0;      
-                    break;
-                case CALIBRATE:
-                    pwmPin.write(0.0);
-                    
-                    
-                    ledR = 1;
-                    ledG = 0;
-                    ledB = 0;
-                    
-                    break;
-            }
-    }
-
-void motorConfig::turnMotorOn(){
-    currentState = ACTIVE; 
+    // Set motor speed
+    if (fabs(motorValue)>1){ 
+        pwmPin = 1.0;
+        }
+    else {
+        pwmPin.write(fabs(motorValue) + 0.4);
+        }
+                          
     }
     
-void motorConfig::killSwitch(){
-    currentState = KILLED;
+void motorConfig::kill(){
+//    currentState = KILLED;
+    pwmPin.write(0.0);
+                
     }
\ No newline at end of file