Stepper motor moves in steps depending on the 4 bit input given by switches

Dependencies:   StepperMotorUni mbed

Committer:
EduRemo
Date:
Fri Feb 05 07:33:38 2016 +0000
Revision:
0:d3f9c4187789
FRCRCE Stepper motor

Who changed what in which revision?

UserRevisionLine numberNew contents of line
EduRemo 0:d3f9c4187789 1 // "Hello" program for StepperMotorUni class library
EduRemo 0:d3f9c4187789 2
EduRemo 0:d3f9c4187789 3
EduRemo 0:d3f9c4187789 4 #include "mbed.h"
EduRemo 0:d3f9c4187789 5 #include "StepperMotorUni.h"
EduRemo 0:d3f9c4187789 6
EduRemo 0:d3f9c4187789 7 StepperMotorUni motor( PTB0, PTB1, PTB2, PTB3);
EduRemo 0:d3f9c4187789 8
EduRemo 0:d3f9c4187789 9 DigitalIn sw0(PTD1); // Switch selected as input
EduRemo 0:d3f9c4187789 10 DigitalIn sw1(PTD3);
EduRemo 0:d3f9c4187789 11 DigitalIn sw2(PTD2);
EduRemo 0:d3f9c4187789 12 DigitalIn sw3(PTD0);
EduRemo 0:d3f9c4187789 13
EduRemo 0:d3f9c4187789 14 int main()
EduRemo 0:d3f9c4187789 15 { motor.set_pps( 200 );
EduRemo 0:d3f9c4187789 16 while (1)
EduRemo 0:d3f9c4187789 17 {
EduRemo 0:d3f9c4187789 18 if (sw0==0 && sw1==0 && sw2==0 && sw3==0)
EduRemo 0:d3f9c4187789 19 {
EduRemo 0:d3f9c4187789 20 motor.move_steps(150);
EduRemo 0:d3f9c4187789 21 }
EduRemo 0:d3f9c4187789 22 else if (sw0==0 && sw1==0 && sw2==0 && sw3==1)
EduRemo 0:d3f9c4187789 23 {
EduRemo 0:d3f9c4187789 24 motor.move_steps(140);
EduRemo 0:d3f9c4187789 25 wait(5);
EduRemo 0:d3f9c4187789 26 }
EduRemo 0:d3f9c4187789 27 else if (sw0==0 && sw1==0 && sw2==1 && sw3==0)
EduRemo 0:d3f9c4187789 28 {
EduRemo 0:d3f9c4187789 29 motor.move_steps(130);
EduRemo 0:d3f9c4187789 30 wait(5);
EduRemo 0:d3f9c4187789 31 }
EduRemo 0:d3f9c4187789 32 else if (sw0==0 && sw1==0 && sw2==1 && sw3==1)
EduRemo 0:d3f9c4187789 33 {
EduRemo 0:d3f9c4187789 34 motor.move_steps(120);
EduRemo 0:d3f9c4187789 35 wait(5);
EduRemo 0:d3f9c4187789 36 }
EduRemo 0:d3f9c4187789 37 else if (sw0==0 && sw1==1 && sw2==0 && sw3==0)
EduRemo 0:d3f9c4187789 38 {
EduRemo 0:d3f9c4187789 39 motor.move_steps(110);
EduRemo 0:d3f9c4187789 40 wait(5);
EduRemo 0:d3f9c4187789 41 }
EduRemo 0:d3f9c4187789 42 else if (sw0==0 && sw1==1 && sw2==0 && sw3==1)
EduRemo 0:d3f9c4187789 43 {
EduRemo 0:d3f9c4187789 44 motor.move_steps(100);
EduRemo 0:d3f9c4187789 45 wait(5);
EduRemo 0:d3f9c4187789 46 }
EduRemo 0:d3f9c4187789 47 else if (sw0==0 && sw1==1 && sw2==1 && sw3==0)
EduRemo 0:d3f9c4187789 48 {
EduRemo 0:d3f9c4187789 49 motor.move_steps(90);
EduRemo 0:d3f9c4187789 50 wait(5);
EduRemo 0:d3f9c4187789 51 }
EduRemo 0:d3f9c4187789 52 else if (sw0==0 && sw1==1 && sw2==1 && sw3==1)
EduRemo 0:d3f9c4187789 53 {
EduRemo 0:d3f9c4187789 54 motor.move_steps(80);
EduRemo 0:d3f9c4187789 55 wait(5);
EduRemo 0:d3f9c4187789 56 }
EduRemo 0:d3f9c4187789 57 else if (sw0==1 && sw1==0 && sw2==0 && sw3==0)
EduRemo 0:d3f9c4187789 58 {
EduRemo 0:d3f9c4187789 59 motor.move_steps(70);
EduRemo 0:d3f9c4187789 60 wait(5);
EduRemo 0:d3f9c4187789 61 }
EduRemo 0:d3f9c4187789 62 else if (sw0==1 && sw1==0 && sw2==0 && sw3==1)
EduRemo 0:d3f9c4187789 63 {
EduRemo 0:d3f9c4187789 64 motor.move_steps(60);
EduRemo 0:d3f9c4187789 65 wait(5);
EduRemo 0:d3f9c4187789 66 }
EduRemo 0:d3f9c4187789 67 else if (sw0==1 && sw1==0 && sw2==1 && sw3==0)
EduRemo 0:d3f9c4187789 68 {
EduRemo 0:d3f9c4187789 69 motor.move_steps(50);
EduRemo 0:d3f9c4187789 70 wait(5);
EduRemo 0:d3f9c4187789 71 }
EduRemo 0:d3f9c4187789 72 else if (sw0==1 && sw1==0 && sw2==1 && sw3==1)
EduRemo 0:d3f9c4187789 73 {
EduRemo 0:d3f9c4187789 74 motor.move_steps(40);
EduRemo 0:d3f9c4187789 75 wait(5);
EduRemo 0:d3f9c4187789 76 }
EduRemo 0:d3f9c4187789 77 else if (sw0==1 && sw1==1 && sw2==0 && sw3==0)
EduRemo 0:d3f9c4187789 78 {
EduRemo 0:d3f9c4187789 79 motor.move_steps(30);
EduRemo 0:d3f9c4187789 80 wait(5);
EduRemo 0:d3f9c4187789 81 }
EduRemo 0:d3f9c4187789 82 else if (sw0==1 && sw1==1 && sw2==0 && sw3==1)
EduRemo 0:d3f9c4187789 83 {
EduRemo 0:d3f9c4187789 84 motor.move_steps(20);
EduRemo 0:d3f9c4187789 85 wait(5);
EduRemo 0:d3f9c4187789 86 }
EduRemo 0:d3f9c4187789 87 else if (sw0==1 && sw1==1 && sw2==1 && sw3==0)
EduRemo 0:d3f9c4187789 88 {
EduRemo 0:d3f9c4187789 89 motor.move_steps(10);
EduRemo 0:d3f9c4187789 90 wait(5);
EduRemo 0:d3f9c4187789 91 }
EduRemo 0:d3f9c4187789 92 else if (sw0==1 && sw1==1 && sw2==1 && sw3==1)
EduRemo 0:d3f9c4187789 93 {
EduRemo 0:d3f9c4187789 94 motor.move_steps(00);
EduRemo 0:d3f9c4187789 95 wait(5);
EduRemo 0:d3f9c4187789 96 }
EduRemo 0:d3f9c4187789 97 else
EduRemo 0:d3f9c4187789 98 {
EduRemo 0:d3f9c4187789 99 motor.move_steps(0);
EduRemo 0:d3f9c4187789 100 }
EduRemo 0:d3f9c4187789 101 }
EduRemo 0:d3f9c4187789 102 }