Small class to control a stepper motor

Dependents:   tuner

Motor.cpp

Committer:
melangeaddict
Date:
2012-11-25
Revision:
0:278f07b2be46

File content as of revision 0:278f07b2be46:

#include "Motor.h"

Motor::Motor(PinName enable,PinName direction,PinName step) : _enable(enable), _direction(direction), _step(step) {
_enable=1;
}

Motor::~Motor() {
}

void Motor::motor_turn(int direction, int steps) {
    _enable=0;
    float freq=600;//frequency of PWM signal to drive stepper motor
    _step.period(1/freq);
    _step.write(.5);
    _direction=direction;
    wait(steps*(1/freq));
    _step.write(0);
    _enable=1;
}