Mouse code for the MacroRat

Dependencies:   ITG3200 QEI

Revision:
4:b5b7836ca2b0
Child:
7:6f5cb6377bd4
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/motor.h	Fri Apr 28 02:13:24 2017 +0000
@@ -0,0 +1,64 @@
+#ifndef MOTOR_H
+#define MOTOR_H
+
+#include "mbed.h"
+#include "main.h"
+
+#define BRAKE_VOLTAGE 0.2
+
+extern PwmOut left1;
+extern PwmOut left2;
+extern PwmOut right1;
+extern PwmOut right2;
+
+inline void rightWheelForward(double voltage) {
+    right1.write(voltage);
+    right2.write(0);
+}
+
+inline void rightWheelBackward(double voltage) {
+    right1.write(0);
+    right2.write(voltage);
+}
+
+inline void leftWheelForward(double voltage) {
+    left1.write(0);
+    left2.write(voltage);
+}
+
+inline void leftWheelBackward(double voltage) {
+    left1.write(voltage);
+    left2.write(0);
+}
+
+inline void brakeLeftWheel() {
+    left1.write(BRAKE_VOLTAGE);
+    left2.write(BRAKE_VOLTAGE);
+}
+
+inline void brakeRightWheel() {
+    right1.write(BRAKE_VOLTAGE);
+    right2.write(BRAKE_VOLTAGE);
+}
+
+inline void brake() {
+    brakeLeftWheel();
+    brakeRightWheel();
+}
+
+inline void coastLeftWheel() {
+    left1.write(0);
+    left2.write(0);
+}
+
+inline void coastRightWheel() {
+    right1.write(0);
+    right2.write(0);
+}
+
+inline void coast() {
+    coastLeftWheel();
+    coastRightWheel();
+}
+
+#endif
\ No newline at end of file