Minh Nguyen / MotorDriver

MotorDriver.cpp

Committer:
khaiminhvn
Date:
2021-02-09
Revision:
0:c58a5bbd417a

File content as of revision 0:c58a5bbd417a:

//INCLUDES
#include "MotorDriver.h"
#include "PinAssignment.h"

MotorDriver::MotorDriver() : ena(PIN_ENA),enb(PIN_ENB),intp(PIN_INTP),intn(PIN_INTN) {}

//moveForward
void MotorDriver::moveForward(int s)
{
    switch(s)
    {
        case M1:
            ena = 1;
            enb = 0;
            break;
        case M2:
            ena = 0;
            enb = 1;
            break;
        case M_ALL:
            ena = 1;
            enb = 1;
            break;
    }
    intp = 1;
    intn = 0;
}

//moveBackward
void MotorDriver::moveBackward(int s)
{
    switch(s)
    {
        case M1:
            ena = 1;
            enb = 0;
            break;
        case M2:
            ena = 0;
            enb = 1;
            break;
        case M_ALL:
            ena = 1;
            enb = 1;
            break;
    }
    intp = 0;
    intn = 1;
}

//stop
void MotorDriver::stop()
{
    ena = 0;
    enb = 0;
    intp = 0;
    intn = 0;
}