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
Revision 0:a1d256e2cd41, committed 2015-05-21
- Comitter:
- thmaure
- Date:
- Thu May 21 14:21:25 2015 +0000
- Commit message:
- moteur pas ? pas
Changed in this revision
diff -r 000000000000 -r a1d256e2cd41 Stepper.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Stepper.cpp Thu May 21 14:21:25 2015 +0000 @@ -0,0 +1,41 @@ +#include "Stepper.h" +#include "mbed.h" + +stepper::stepper(PinName _en, PinName ms1, PinName ms2, PinName ms3, PinName _stepPin, PinName dir):en(_en), + microstepping(ms1, ms2, ms3), + stepPin(_stepPin), + direction(dir) +{ +} + +void stepper::step(int microstep, int dir, float speed) +{ + if (microstep == 1) { + microstepping = 0; + } else if (microstep <= 4) { + microstepping = microstep / 2; + } else if (microstep > 4) { + microstepping = (microstep / 2) - 1; + } + if (dir == 1) { + direction = 0; + } else if (dir == 0) { + direction = 1; + } + + // Step... + stepPin = 1; + wait(1/speed); + stepPin = 0; + wait(1/speed); +} + +void stepper::enable() +{ + en = 0; +} + +void stepper::disable() +{ + en = 1; +} \ No newline at end of file
diff -r 000000000000 -r a1d256e2cd41 Stepper.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Stepper.h Thu May 21 14:21:25 2015 +0000 @@ -0,0 +1,19 @@ +#ifndef MBED_STEPPER_H +#define MBED_STEPPER_H +#endif + +#include "mbed.h" + +class stepper +{ +public: + stepper(PinName _en, PinName ms1, PinName ms2, PinName ms3, PinName _stepPin, PinName dir); + void step(int microstep, int dir, float speed); + void enable(); + void disable(); +private: + DigitalOut en; + BusOut microstepping; + DigitalOut stepPin; + DigitalOut direction; +}; \ No newline at end of file
diff -r 000000000000 -r a1d256e2cd41 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Thu May 21 14:21:25 2015 +0000 @@ -0,0 +1,20 @@ +#include "mbed.h" + +DigitalOut enable(D2); +PwmOut step(D3); +PwmOut led(LED2); +DigitalInOut mybut(USER_BUTTON); + +int main() { + + enable=1; + step.period_ms(10); + step.pulsewidth_ms(5); + while(1){ + + enable=0; + wait(0.1); + enable=1; + wait(0.4); + } +} \ No newline at end of file
diff -r 000000000000 -r a1d256e2cd41 mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Thu May 21 14:21:25 2015 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/487b796308b0 \ No newline at end of file