Doesn't hit the ends

Dependencies:   Motordriver QEI mbed

Revision:
0:e881319cfd74
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Fri Oct 21 11:28:55 2016 +0000
@@ -0,0 +1,76 @@
+#include "QEI.h"
+#include "mbed.h"
+#include "motordriver.h"
+
+//======== Serial Communication ================================================
+Serial pc(USBTX, USBRX);
+
+
+//======== Motor and QEI =======================================================
+QEI wheel (D12, D13, NC, 62);
+
+//Safety for Motor
+int Brakeable;
+int sign;
+
+//Motor
+Motor A(D6, D7, D7, Brakeable); // pwm, fwd, rev, brake          LEFT
+
+
+//======== Miscellaneous =======================================================
+AnalogIn pot(A1);               //Potmeter
+DigitalOut led(LED_GREEN);      //Green LED
+InterruptIn btn(SW2);           //Button
+InterruptIn btn2(SW3);          //Button
+
+
+//======== Variables ===========================================================
+float factor = 0.03279;
+int position;
+float ain;   /* Variable to store the analog input*/
+
+
+
+
+//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+//======== Functions and main ==================================================
+int main() {
+   while(1){
+   
+   if(btn && btn2) {   
+        A.speed(0)==0;
+      
+   }else if(btn && !btn2){
+        if(position <= -105){
+        A.speed(0.2)==0.2;
+    
+        }else{
+        A.speed(-0.5)==-0.5;
+        }
+    
+    }else if(!btn && btn2){
+        if(position >= 105){
+        A.speed(-0.2)==-0.2;
+    
+        }else{
+        A.speed(0.5)==0.5;
+        }
+    }
+    
+    else{
+    A.speed(0)==0;
+    }   
+    
+    position = (wheel.getPulses()*factor) ; // position of the motor      
+    ain = pot.read();
+   
+            if (ain == 0){
+                wheel.reset();   
+            }
+            else {}
+        wait(0.1);
+        pc.baud(115200);
+        pc.printf("Afgelegde milimeters is: %i\n", position);
+    }
+
+}