Control Motor A and B with buttons

Dependencies:   Motordriver QEI mbed

Revision:
0:442257145c29
diff -r 000000000000 -r 442257145c29 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Mon Oct 03 13:47:29 2016 +0000
@@ -0,0 +1,58 @@
+#include "mbed.h"
+#include "motordriver.h"
+
+//LED
+//*Note: false = on, true = off*
+DigitalOut ledB(LED_BLUE);
+DigitalOut ledR(LED_RED);
+DigitalOut ledG(LED_GREEN);
+
+
+//Safety for Motor
+int Brakeable; //cna the motor driver break
+int sign; //prevents throwing the motor from full foward to full reverse and stuff melting.
+
+//Motor
+Motor A(D6, D7, D7, Brakeable); // pwm, fwd, rev, brake
+Motor B(D5, D4, D4, Brakeable); // pwm, fwd, rev, brake
+
+
+//Button
+InterruptIn btn(SW2);
+InterruptIn btn2(SW3);
+
+
+int main() {
+
+  while(true) {
+           
+        if(btn && btn2) {                   //If SW2 and SW3 aren't pressed
+            A.speed(0) == 0;               //If speed is 0, the motor doensn't rotate.
+            B.speed(0) == 0;             
+            ledR = false;                   
+            ledG = true;                    
+            ledB = true;                    
+        } else if (btn && !btn2) {          //If SW3 is pressed
+            A.speed(0.1) == 0.1;           //If the speed is positive, the motor rotates left/right. The maximum speed is 1.
+            B.speed(0.1) == 0.1;
+            ledR = true;
+            ledG = false;
+            ledB = true;            
+        } else if (!btn && btn2) {          //If SW2 is pressed
+            A.speed(-0.1) == -0.1;          //If the speed is negative, the motor rotates left/right. The maximum speed is -1.
+            B.speed(-0.1) == -0.1;
+            ledR = true;
+            ledG = true;
+            ledB = false;            
+        } else {                            //If SW2 and SW3 are pressed
+            A.speed(0) == 0;               //If speed is 0, the motor doensn't rotate.
+            B.speed(0) == 0;
+            ledR = true;
+            ledG = true;
+            ledB = true;
+        }
+
+      }
+    }
+    
+