![](/media/cache/group/Download.jpg.50x50_q85.jpg)
6.13 Schrittmotor bis zum Endschalter laufen lassen, Nullpunkt setzen, 10 x 100 Schritte vorwärts und in einem Lauf zurück auf die Nullposition. Zusätzlich einen Button als Notaus (Soforthalt) vorsehen. Anwendung: 3D Drucker, Plotter, CNC Fräse.
Dependencies: StepperMotorUni mbed
Fork of IoTKit_StepperMotor by
Diff: main.cpp
- Revision:
- 2:a0607b1417da
- Parent:
- 1:1330fe477c67
--- a/main.cpp Sat Jan 03 14:31:09 2015 +0000 +++ b/main.cpp Wed Mar 04 16:35:56 2015 +0000 @@ -1,26 +1,44 @@ -/** - * Schrittmotor (unipolar) Beispiel. - * @see http://developer.mbed.org/components/Stepper-motor-unipolar/ - * - * Die verwendeten Pins spielen keine Rolle. +/** 6.13 Schrittmotor bis zum Endschalter laufen lassen, Nullpunkt setzen, 10 x 100 Schritte vorwärts + und in einem Lauf zurück auf die Nullposition. Zusätzlich einen Button als Notaus (Soforthalt) vorsehen. + Anwendung: 3D Drucker, Plotter, CNC Fräse. */ #include "mbed.h" #include "StepperMotorUni.h" -StepperMotorUni motor( D4, D5, D6, D7 ); +// Schrittmotor +StepperMotorUni motor( PTB18, PTB19, PTC1, PTC8 ); +// Endabschalter +DigitalIn home( A3, PullUp ); +// Notstop +DigitalIn stop ( PTC9, PullUp ); int main() { // Motordrehzahl + printf( "Schrittmotor Test\n" ); motor.set_pps( 300 ); while ( 1 ) { - motor.move_steps( 2000 ); - wait( 8 ); + printf( "vorwaerts\n" ); + int steps = 10; + for ( int i = 0; i < 2048; i += steps ) + { + motor.move_steps( steps ); + if ( home == 0 ) + break; + if ( stop == 0 ) + return( -1 ); + wait( 0.1 ); + } - motor.move_steps( -2000 ); - wait( 8 ); + printf( "rueckwaerts\n" ); + motor.move_steps( -1024 ); + wait( 5.0 ); + + printf( "in die Mitte\n" ); + motor.move_steps( 512 ); + wait( 2.5 ); } }