afsd
Fork of a4998 by
a4988.cpp@0:173936452e07, 2018-05-02 (annotated)
- Committer:
- glintligo
- Date:
- Wed May 02 10:48:23 2018 +0000
- Revision:
- 0:173936452e07
- Child:
- 1:88f743f3e7a7
fsdaf
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" |
glintligo | 0:173936452e07 | 3 | Stepper::Stepper(PinName _en, PinName _stepPin, PinName _direction):en(_en), |
glintligo | 0:173936452e07 | 4 | stepPin(_stepPin), |
glintligo | 0:173936452e07 | 5 | direction(_direction) |
glintligo | 0:173936452e07 | 6 | { |
glintligo | 0:173936452e07 | 7 | |
glintligo | 0:173936452e07 | 8 | } |
glintligo | 0:173936452e07 | 9 | |
glintligo | 0:173936452e07 | 10 | void Stepper::step(int dir, int frequency ,volatile int _remain) |
glintligo | 0:173936452e07 | 11 | { |
glintligo | 0:173936452e07 | 12 | //fun = &Stepper::step_control; |
glintligo | 0:173936452e07 | 13 | if (dir == 1) { |
glintligo | 0:173936452e07 | 14 | direction = 0; |
glintligo | 0:173936452e07 | 15 | } else if (dir == 0) { |
glintligo | 0:173936452e07 | 16 | direction = 1; |
glintligo | 0:173936452e07 | 17 | } |
glintligo | 0:173936452e07 | 18 | remain = _remain; |
glintligo | 0:173936452e07 | 19 | step_ticker.attach(this, &Stepper::step_control,1.0/frequency); |
glintligo | 0:173936452e07 | 20 | } |
glintligo | 0:173936452e07 | 21 | |
glintligo | 0:173936452e07 | 22 | void Stepper::enable() |
glintligo | 0:173936452e07 | 23 | { |
glintligo | 0:173936452e07 | 24 | en = 0; |
glintligo | 0:173936452e07 | 25 | } |
glintligo | 0:173936452e07 | 26 | |
glintligo | 0:173936452e07 | 27 | void Stepper::disable() |
glintligo | 0:173936452e07 | 28 | { |
glintligo | 0:173936452e07 | 29 | en = 1; |
glintligo | 0:173936452e07 | 30 | } |
glintligo | 0:173936452e07 | 31 | |
glintligo | 0:173936452e07 | 32 | void Stepper::step_control() |
glintligo | 0:173936452e07 | 33 | { |
glintligo | 0:173936452e07 | 34 | if(remain == 0) |
glintligo | 0:173936452e07 | 35 | { |
glintligo | 0:173936452e07 | 36 | return; |
glintligo | 0:173936452e07 | 37 | } |
glintligo | 0:173936452e07 | 38 | |
glintligo | 0:173936452e07 | 39 | if(stepPin){ |
glintligo | 0:173936452e07 | 40 | stepPin = 0; //STEP 1->0 |
glintligo | 0:173936452e07 | 41 | remain--; |
glintligo | 0:173936452e07 | 42 | }else{ |
glintligo | 0:173936452e07 | 43 | stepPin = 1; //STEP 0->1 |
glintligo | 0:173936452e07 | 44 | } |
glintligo | 0:173936452e07 | 45 | } |