6.6 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.

Dependencies:   StepperMotorUni mbed

Fork of 06-13-Uebung by th.iotkit1.ch

Committer:
stefan1691
Date:
Mon Nov 07 09:57:37 2016 +0000
Revision:
4:e774091a811e
Parent:
3:1b56d15b0964
Anschluss an Stepper 1

Who changed what in which revision?

UserRevisionLine numberNew contents of line
stefan1691 3:1b56d15b0964 1 /** 6.6 Schrittmotor bis zum Endschalter laufen lassen, Nullpunkt setzen, 10 x 100 Schritte vorwärts
marcel1691 2:a0607b1417da 2 und in einem Lauf zurück auf die Nullposition. Zusätzlich einen Button als Notaus (Soforthalt) vorsehen.
marcel1691 2:a0607b1417da 3 Anwendung: 3D Drucker, Plotter, CNC Fräse.
okano 0:ae2206213141 4 */
okano 0:ae2206213141 5
okano 0:ae2206213141 6 #include "mbed.h"
okano 0:ae2206213141 7 #include "StepperMotorUni.h"
okano 0:ae2206213141 8
marcel1691 2:a0607b1417da 9 // Schrittmotor
stefan1691 4:e774091a811e 10 StepperMotorUni motor( D5, D4, D3, D2 );
marcel1691 2:a0607b1417da 11 // Endabschalter
stefan1691 3:1b56d15b0964 12 DigitalIn home( A4 );
marcel1691 2:a0607b1417da 13 // Notstop
stefan1691 3:1b56d15b0964 14 DigitalIn stop ( A2 );
okano 0:ae2206213141 15
okano 0:ae2206213141 16 int main()
okano 0:ae2206213141 17 {
marcel1691 1:1330fe477c67 18 // Motordrehzahl
marcel1691 2:a0607b1417da 19 printf( "Schrittmotor Test\n" );
marcel1691 1:1330fe477c67 20 motor.set_pps( 300 );
okano 0:ae2206213141 21
marcel1691 1:1330fe477c67 22 while ( 1 )
marcel1691 1:1330fe477c67 23 {
marcel1691 2:a0607b1417da 24 printf( "vorwaerts\n" );
marcel1691 2:a0607b1417da 25 int steps = 10;
marcel1691 2:a0607b1417da 26 for ( int i = 0; i < 2048; i += steps )
marcel1691 2:a0607b1417da 27 {
marcel1691 2:a0607b1417da 28 motor.move_steps( steps );
marcel1691 2:a0607b1417da 29 if ( home == 0 )
marcel1691 2:a0607b1417da 30 break;
marcel1691 2:a0607b1417da 31 if ( stop == 0 )
marcel1691 2:a0607b1417da 32 return( -1 );
marcel1691 2:a0607b1417da 33 wait( 0.1 );
marcel1691 2:a0607b1417da 34 }
okano 0:ae2206213141 35
marcel1691 2:a0607b1417da 36 printf( "rueckwaerts\n" );
marcel1691 2:a0607b1417da 37 motor.move_steps( -1024 );
marcel1691 2:a0607b1417da 38 wait( 5.0 );
marcel1691 2:a0607b1417da 39
marcel1691 2:a0607b1417da 40 printf( "in die Mitte\n" );
marcel1691 2:a0607b1417da 41 motor.move_steps( 512 );
marcel1691 2:a0607b1417da 42 wait( 2.5 );
okano 0:ae2206213141 43 }
okano 0:ae2206213141 44 }