Homing system

homingsystem.cpp

Committer:
maaikelaagland
Date:
2017-10-31
Revision:
0:c49ff6a6ebee

File content as of revision 0:c49ff6a6ebee:

 #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;
    }