beta1
Fork of a4998 by
a4988.cpp
- Committer:
- glintligo
- Date:
- 2018-07-16
- Revision:
- 2:57c57267b1da
- Parent:
- 1:209911ee18cd
- Child:
- 3:9e9f3cd7fff0
File content as of revision 2:57c57267b1da:
#include "a4988.h" #include "mbed.h" Stepper::Stepper(PinName _en, PinName _stepPin, PinName _direction):en(_en), stepPin(_stepPin), direction(_direction) { } void Stepper::step(int dir, int frequency ,volatile int _remain) { if (dir == 1) { direction = 0; } else if (dir == 0) { direction = 1; } else { return; } remain = _remain; step_ticker.attach(callback(this, &Stepper::step_control),0.5/frequency); } void Stepper::enable() { en = 0; } void Stepper::disable() { en = 1; } void Stepper::step_control() { if(remain <= 0) { step_ticker.detach(); return; } if(stepPin){ stepPin = 0; //STEP 1->0 remain--; }else{ stepPin = 1; //STEP 0->1 } } void Stepper::longrun(int dir, int frequency) { if (dir == 1) { direction = 0; } else if (dir == 0) { direction = 1; } else { return; } step_ticker.attach(callback(this, &Stepper::run_control),0.5/frequency); } void Stepper::run_control() { if(stepPin){ stepPin = 0; //STEP 1->0 remain--; }else{ stepPin = 1; //STEP 0->1 } } void Stepper::stoprun() { step_ticker.detach(); }