ze chen
/
Stepper_4
fold
Fork of Stepper_4 by
Revision 1:9393a7e6b1d6, committed 2014-09-20
- Comitter:
- zchen311
- Date:
- Sat Sep 20 14:49:22 2014 +0000
- Parent:
- 0:6999a083fb46
- Commit message:
- new project;
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
sMotor.lib | Show annotated file Show diff for this revision Revisions of this file |
diff -r 6999a083fb46 -r 9393a7e6b1d6 main.cpp --- a/main.cpp Thu Jun 14 12:18:18 2012 +0000 +++ b/main.cpp Sat Sep 20 14:49:22 2014 +0000 @@ -15,13 +15,17 @@ Serial pc(USBTX, USBRX); sMotor motor(p9, p10, p11, p12); // creates new stepper motor: IN1, IN2, IN3, IN4 - +DigitalOut myled1(LED1); +DigitalOut myled2(LED2); +DigitalOut myled3(LED3); +DigitalOut myled4(LED4); int step_speed = 1200 ; // set default motor speed int numstep = 512 ; // defines full turn of 360 degree //you might want to calibrate this value according to your motor -int main() { +int main() +{ //Credits printf("4 Phase Stepper Motor v0.1 - Test Program\r\n"); @@ -36,22 +40,32 @@ printf("4- 180 degree anticlockwise step\n\r"); printf("5- Change Speed\n\r"); + myled1=1; + wait(0.2); + myled1=0; + wait(0.2); + while (1) { + if (pc.readable()) { // checks for serial - - if (pc.getc()=='1') + printf("ask for input"); + if (pc.getc()=='1'){ motor.step(numstep,0,step_speed); // number of steps, direction, speed - - if (pc.getc()=='2') + myled1=1;myled2=0;myled3=0;myled4=0; + } + if (pc.getc()=='2'){ motor.step(numstep,1,step_speed); - - if (pc.getc()=='3') + myled1=0;myled2=1;myled3=0;myled4=0; + } + if (pc.getc()=='3'){ motor.step(numstep/2,0,step_speed); - - if (pc.getc()=='4') + myled1=0;myled2=0;myled3=1;myled4=0; + } + if (pc.getc()=='4'){ motor.step(numstep/2,1,step_speed); - + myled1=0;myled2=0;myled3=0;myled4=1; + } if (pc.getc()=='5') { printf("Current Speed: %d\n\r", step_speed); printf("New speed: \n\r");
diff -r 6999a083fb46 -r 9393a7e6b1d6 sMotor.lib --- a/sMotor.lib Thu Jun 14 12:18:18 2012 +0000 +++ b/sMotor.lib Sat Sep 20 14:49:22 2014 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/XtaticO/code/sMotor/#4b3b9e047ce3 +http://mbed.org/users/zchen311/code/sMotor/#cf4869aef47f