Mouse code for the MacroRat

Dependencies:   ITG3200 QEI

motor.cpp

Committer:
christine222
Date:
23 months ago
Revision:
13:2032db00f168
Parent:
12:5790e56a056f
Child:
15:b80555a4a8b9

File content as of revision 13:2032db00f168:

#include "mbed.h"
#include "motor.h"

void Motor::backward(double voltage) {
    if(voltage > maxSpeed){
        voltage = maxSpeed;
    }else if(voltage < minSpeed){
        voltage = minSpeed;
    }
    forw.write(voltage);
    back.write(0);
}

void Motor::forward(double voltage) {
    if(voltage > maxSpeed){
        voltage = maxSpeed;
    }else if(voltage < minSpeed){
        voltage = minSpeed;
    }
    forw.write(0);
    back.write(voltage);
}

void Motor::move(double voltage) {
    if(voltage < 0){
        backward(-voltage);
    }
    if(voltage > 0){
        forward(voltage);
    }
}


void Motor::brake() {
    forw.write(BRAKE_VOLTAGE);
    back.write(BRAKE_VOLTAGE);
}

void Motor::coast() {
    forw.write(0);
    back.write(0);
}