Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
Stepper.cpp@0:a1d256e2cd41, 2015-05-21 (annotated)
- Committer:
- thmaure
- Date:
- Thu May 21 14:21:25 2015 +0000
- Revision:
- 0:a1d256e2cd41
moteur pas ? pas
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
thmaure | 0:a1d256e2cd41 | 1 | #include "Stepper.h" |
thmaure | 0:a1d256e2cd41 | 2 | #include "mbed.h" |
thmaure | 0:a1d256e2cd41 | 3 | |
thmaure | 0:a1d256e2cd41 | 4 | stepper::stepper(PinName _en, PinName ms1, PinName ms2, PinName ms3, PinName _stepPin, PinName dir):en(_en), |
thmaure | 0:a1d256e2cd41 | 5 | microstepping(ms1, ms2, ms3), |
thmaure | 0:a1d256e2cd41 | 6 | stepPin(_stepPin), |
thmaure | 0:a1d256e2cd41 | 7 | direction(dir) |
thmaure | 0:a1d256e2cd41 | 8 | { |
thmaure | 0:a1d256e2cd41 | 9 | } |
thmaure | 0:a1d256e2cd41 | 10 | |
thmaure | 0:a1d256e2cd41 | 11 | void stepper::step(int microstep, int dir, float speed) |
thmaure | 0:a1d256e2cd41 | 12 | { |
thmaure | 0:a1d256e2cd41 | 13 | if (microstep == 1) { |
thmaure | 0:a1d256e2cd41 | 14 | microstepping = 0; |
thmaure | 0:a1d256e2cd41 | 15 | } else if (microstep <= 4) { |
thmaure | 0:a1d256e2cd41 | 16 | microstepping = microstep / 2; |
thmaure | 0:a1d256e2cd41 | 17 | } else if (microstep > 4) { |
thmaure | 0:a1d256e2cd41 | 18 | microstepping = (microstep / 2) - 1; |
thmaure | 0:a1d256e2cd41 | 19 | } |
thmaure | 0:a1d256e2cd41 | 20 | if (dir == 1) { |
thmaure | 0:a1d256e2cd41 | 21 | direction = 0; |
thmaure | 0:a1d256e2cd41 | 22 | } else if (dir == 0) { |
thmaure | 0:a1d256e2cd41 | 23 | direction = 1; |
thmaure | 0:a1d256e2cd41 | 24 | } |
thmaure | 0:a1d256e2cd41 | 25 | |
thmaure | 0:a1d256e2cd41 | 26 | // Step... |
thmaure | 0:a1d256e2cd41 | 27 | stepPin = 1; |
thmaure | 0:a1d256e2cd41 | 28 | wait(1/speed); |
thmaure | 0:a1d256e2cd41 | 29 | stepPin = 0; |
thmaure | 0:a1d256e2cd41 | 30 | wait(1/speed); |
thmaure | 0:a1d256e2cd41 | 31 | } |
thmaure | 0:a1d256e2cd41 | 32 | |
thmaure | 0:a1d256e2cd41 | 33 | void stepper::enable() |
thmaure | 0:a1d256e2cd41 | 34 | { |
thmaure | 0:a1d256e2cd41 | 35 | en = 0; |
thmaure | 0:a1d256e2cd41 | 36 | } |
thmaure | 0:a1d256e2cd41 | 37 | |
thmaure | 0:a1d256e2cd41 | 38 | void stepper::disable() |
thmaure | 0:a1d256e2cd41 | 39 | { |
thmaure | 0:a1d256e2cd41 | 40 | en = 1; |
thmaure | 0:a1d256e2cd41 | 41 | } |