dsaf
Fork of a4998 by
a4988.cpp@1:ab0f997c2d9c, 2018-05-08 (annotated)
- Committer:
- brainliang
- Date:
- Tue May 08 01:19:00 2018 +0000
- Revision:
- 1:ab0f997c2d9c
- Parent:
- 0:173936452e07
fds
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
glintligo | 0:173936452e07 | 1 | #include "a4988.h" |
glintligo | 0:173936452e07 | 2 | #include "mbed.h" |
brainliang | 1:ab0f997c2d9c | 3 | Stepper::Stepper(PinName _en, PinName _stepPin, PinName _direction): |
brainliang | 1:ab0f997c2d9c | 4 | en(_en), |
glintligo | 0:173936452e07 | 5 | stepPin(_stepPin), |
glintligo | 0:173936452e07 | 6 | direction(_direction) |
glintligo | 0:173936452e07 | 7 | { |
glintligo | 0:173936452e07 | 8 | |
glintligo | 0:173936452e07 | 9 | } |
glintligo | 0:173936452e07 | 10 | |
glintligo | 0:173936452e07 | 11 | void Stepper::step(int dir, int frequency ,volatile int _remain) |
glintligo | 0:173936452e07 | 12 | { |
glintligo | 0:173936452e07 | 13 | //fun = &Stepper::step_control; |
glintligo | 0:173936452e07 | 14 | if (dir == 1) { |
glintligo | 0:173936452e07 | 15 | direction = 0; |
glintligo | 0:173936452e07 | 16 | } else if (dir == 0) { |
glintligo | 0:173936452e07 | 17 | direction = 1; |
glintligo | 0:173936452e07 | 18 | } |
glintligo | 0:173936452e07 | 19 | remain = _remain; |
glintligo | 0:173936452e07 | 20 | step_ticker.attach(this, &Stepper::step_control,1.0/frequency); |
glintligo | 0:173936452e07 | 21 | } |
glintligo | 0:173936452e07 | 22 | |
glintligo | 0:173936452e07 | 23 | void Stepper::enable() |
glintligo | 0:173936452e07 | 24 | { |
glintligo | 0:173936452e07 | 25 | en = 0; |
glintligo | 0:173936452e07 | 26 | } |
glintligo | 0:173936452e07 | 27 | |
glintligo | 0:173936452e07 | 28 | void Stepper::disable() |
glintligo | 0:173936452e07 | 29 | { |
glintligo | 0:173936452e07 | 30 | en = 1; |
glintligo | 0:173936452e07 | 31 | } |
glintligo | 0:173936452e07 | 32 | |
glintligo | 0:173936452e07 | 33 | void Stepper::step_control() |
glintligo | 0:173936452e07 | 34 | { |
glintligo | 0:173936452e07 | 35 | if(remain == 0) |
glintligo | 0:173936452e07 | 36 | { |
glintligo | 0:173936452e07 | 37 | return; |
brainliang | 1:ab0f997c2d9c | 38 | }else if(stepPin){ |
brainliang | 1:ab0f997c2d9c | 39 | stepPin = 0; //STEP 1->0 |
brainliang | 1:ab0f997c2d9c | 40 | remain--; |
brainliang | 1:ab0f997c2d9c | 41 | }else{ |
brainliang | 1:ab0f997c2d9c | 42 | stepPin = 1; //STEP 0->1 |
glintligo | 0:173936452e07 | 43 | } |
glintligo | 0:173936452e07 | 44 | } |