Mouse code for the MacroRat

Dependencies:   ITG3200 QEI

Revision:
12:5790e56a056f
Parent:
8:a0760acdc59e
Child:
13:2032db00f168
diff -r 8fc2b703086b -r 5790e56a056f motor.cpp
--- a/motor.cpp	Sun May 07 01:13:42 2017 +0000
+++ b/motor.cpp	Fri May 12 23:25:07 2017 +0000
@@ -2,15 +2,34 @@
 #include "motor.h"
 
 void Motor::backward(double voltage) {
+    if(voltage > maxSpeed){
+        voltage = maxSpeed;
+    }else if(voltage < 0){
+        voltage = 0.0;
+    }
     forw.write(voltage);
     back.write(0);
 }
 
 void Motor::forward(double voltage) {
+    if(voltage > maxSpeed){
+        voltage = maxSpeed;
+    }else if(voltage < 0){
+        voltage = 0.0;
+    }
     forw.write(0);
     back.write(voltage);
 }
 
+void Motor::move(double voltage) {
+    if(voltage < 0){
+        backward(voltage);
+    }
+    if(voltage > 0){
+        forward(voltage);
+    }
+}
+
 
 void Motor::brake() {
     forw.write(BRAKE_VOLTAGE);