Fiona Lin / Mbed OS cap_sense

stepper.cpp

Committer:
fionalin
Date:
2022-06-28
Revision:
0:4e3ad938564e
Child:
1:40e5ac1119a6

File content as of revision 0:4e3ad938564e:

#include <mbed.h>
#include "stepper.h"
#include <chrono>
//#include <thread>

StepperMotor::StepperMotor(PinName enable_pin, PinName step_pin, 
                           PinName dir_pin, PinName ms1_pin, PinName ms2_pin, 
                           PinName ms3_pin)
    : enable(enable_pin), step(step_pin), dir(dir_pin), ms1(ms1_pin), 
      ms2(ms2_pin), ms3(ms3_pin), count(0) {
    enable = 1;
}
      
void StepperMotor::step_positive() {
    dir = 1;
    step = 1;
//    ThisThread::sleep_for(1us);
    step = 0;
    count++;
}

void StepperMotor::step_negative() {
    dir = 0;
    step = 1;
//    ThisThread::sleep_for(1us);
    step = 0;
    count++;
}

int32_t StepperMotor::get_steps() {
    return count;
}

void StepperMotor::reset_step_count() {
    count = 0;
}