Homing system

Files at this revision

API Documentation at this revision

Comitter:
maaikelaagland
Date:
Tue Oct 31 16:16:34 2017 +0000
Commit message:
homing system ;

Changed in this revision

homingsystem.cpp Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/homingsystem.cpp	Tue Oct 31 16:16:34 2017 +0000
@@ -0,0 +1,69 @@
+ #include "QEI.h"
+#include "Servo.h"
+#include "mbed.h"
+ 
+Serial pc(USBTX, USBRX);
+//Use X4 encoding.
+//QEI wheel(p29, p30, NC, 624, QEI::X4_ENCODING);
+//Use X2 encoding by default.
+QEI wheel1(D10, D11, NC, 32);
+QEI wheel2(D13, D12, NC, 32); //enable the encoder
+PwmOut motor1_speed(D6);
+PwmOut motor2_speed(D5);
+DigitalOut motor1_direction (D7);
+DigitalOut motor2_direction(D4);
+AnalogIn potmeter(A0);
+AnalogIn potmeter2(A1);
+InterruptIn button(D8);
+DigitalIn button2(D2);
+DigitalIn button3(D3); //deze 
+DigitalOut led(D3);
+Ticker motor_update;
+
+
+
+float motor1_set_speed= 0;  //dit is x procent van het volledige snelheid
+float motor2_set_speed= 0; 
+float position; 
+
+void motor_control(){
+motor1_speed.write(motor1_set_speed);
+motor2_speed.write(motor2_set_speed);
+motor1_direction.write(1); //hij gaat één kant op 
+motor2_direction.write(1);
+
+ }
+ 
+ void homing_system () {
+         pc.baud(115200);
+    motor_update.attach(motor_control,0.1);
+    button2.mode(PullDown);
+    button3.mode(PullDown);
+    while (true){
+   
+        if (button == 0){
+          motor1_set_speed = 0.15;
+          }  
+
+        if (button2 ==  1){
+            motor1_set_speed = 0;
+            motor2_set_speed=0.15;
+            }
+        if (button3 == 1) {
+            
+            motor2_set_speed = 0;
+            float position = 0;
+            }
+            
+            if (button2 == 1 && button3 ==1) {
+                break;
+                }
+}
+}
+     
+
+ 
+int main(){
+    homing_system ();
+    return 0;
+    }
\ No newline at end of file