hezhian hezhain / armtest

Fork of stepper by Xiaoyuan Yu

stepper.cpp

Committer:
Dennis_Yu
Date:
2018-07-25
Revision:
1:bbb51c42e7d2
Parent:
0:0774a793a83b
Child:
2:e537d08c705b

File content as of revision 1:bbb51c42e7d2:

#include "mbed.h"
#include "stepper.h"

void stepperMotor::init()
{
    remain = 0;
    en = 0;
    dir = 0;

}

void stepper::moveStepper()
{
    if(remain == 0)
        return;
    if(step)
    {
        step = 0; //STEP 1->0
        remain--;
    }
    else
    {
        step = 1; //STEP 0->1
    }
}

void stepper::stepperMotor(PinName stepPin, PinName dirPin, PinName enPin, float period):step(stepPin), dir(dirPin), en(enPin), remain(0)
{
    stepper.attach(&moveStepper, period);
}