Pablo Lopez
/
Stepper_4FERNEY
MOTOR PASO A PASO
Fork of Stepper_4 by
main.cpp@0:6999a083fb46, 2012-06-14 (annotated)
- Committer:
- XtaticO
- Date:
- Thu Jun 14 12:18:18 2012 +0000
- Revision:
- 0:6999a083fb46
- Child:
- 1:be5a5f38621d
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
XtaticO | 0:6999a083fb46 | 1 | /* |
XtaticO | 0:6999a083fb46 | 2 | ############################################ |
XtaticO | 0:6999a083fb46 | 3 | ## sMotor v0.1 Test Program ## |
XtaticO | 0:6999a083fb46 | 4 | ## created by Samuel Matildes ## |
XtaticO | 0:6999a083fb46 | 5 | ############################################ |
XtaticO | 0:6999a083fb46 | 6 | ---- sam.naeec@gmail.com ----- |
XtaticO | 0:6999a083fb46 | 7 | This library was made for 4-Phase Stepper Motors |
XtaticO | 0:6999a083fb46 | 8 | I don't take any resposability for the damage caused to your equipment. |
XtaticO | 0:6999a083fb46 | 9 | |
XtaticO | 0:6999a083fb46 | 10 | */ |
XtaticO | 0:6999a083fb46 | 11 | |
XtaticO | 0:6999a083fb46 | 12 | #include "mbed.h" |
XtaticO | 0:6999a083fb46 | 13 | #include "sMotor.h" |
XtaticO | 0:6999a083fb46 | 14 | |
XtaticO | 0:6999a083fb46 | 15 | |
XtaticO | 0:6999a083fb46 | 16 | Serial pc(USBTX, USBRX); |
XtaticO | 0:6999a083fb46 | 17 | sMotor motor(p9, p10, p11, p12); // creates new stepper motor: IN1, IN2, IN3, IN4 |
XtaticO | 0:6999a083fb46 | 18 | |
XtaticO | 0:6999a083fb46 | 19 | int step_speed = 1200 ; // set default motor speed |
XtaticO | 0:6999a083fb46 | 20 | int numstep = 512 ; // defines full turn of 360 degree |
XtaticO | 0:6999a083fb46 | 21 | //you might want to calibrate this value according to your motor |
XtaticO | 0:6999a083fb46 | 22 | |
XtaticO | 0:6999a083fb46 | 23 | |
XtaticO | 0:6999a083fb46 | 24 | int main() { |
XtaticO | 0:6999a083fb46 | 25 | |
XtaticO | 0:6999a083fb46 | 26 | //Credits |
XtaticO | 0:6999a083fb46 | 27 | printf("4 Phase Stepper Motor v0.1 - Test Program\r\n"); |
XtaticO | 0:6999a083fb46 | 28 | printf("developed by Samuel Matildes\r\n"); |
XtaticO | 0:6999a083fb46 | 29 | printf("\n\r"); |
XtaticO | 0:6999a083fb46 | 30 | |
XtaticO | 0:6999a083fb46 | 31 | // Screen Menu |
XtaticO | 0:6999a083fb46 | 32 | printf("Default Speed: %d\n\r",step_speed); |
XtaticO | 0:6999a083fb46 | 33 | printf("1- 360 degree clockwise step\n\r"); |
XtaticO | 0:6999a083fb46 | 34 | printf("2- 360 degree anticlockwise step\n\r"); |
XtaticO | 0:6999a083fb46 | 35 | printf("3- 180 degree clockwise step\n\r"); |
XtaticO | 0:6999a083fb46 | 36 | printf("4- 180 degree anticlockwise step\n\r"); |
XtaticO | 0:6999a083fb46 | 37 | printf("5- Change Speed\n\r"); |
XtaticO | 0:6999a083fb46 | 38 | |
XtaticO | 0:6999a083fb46 | 39 | while (1) { |
XtaticO | 0:6999a083fb46 | 40 | |
XtaticO | 0:6999a083fb46 | 41 | if (pc.readable()) { // checks for serial |
XtaticO | 0:6999a083fb46 | 42 | |
XtaticO | 0:6999a083fb46 | 43 | if (pc.getc()=='1') |
XtaticO | 0:6999a083fb46 | 44 | motor.step(numstep,0,step_speed); // number of steps, direction, speed |
XtaticO | 0:6999a083fb46 | 45 | |
XtaticO | 0:6999a083fb46 | 46 | if (pc.getc()=='2') |
XtaticO | 0:6999a083fb46 | 47 | motor.step(numstep,1,step_speed); |
XtaticO | 0:6999a083fb46 | 48 | |
XtaticO | 0:6999a083fb46 | 49 | if (pc.getc()=='3') |
XtaticO | 0:6999a083fb46 | 50 | motor.step(numstep/2,0,step_speed); |
XtaticO | 0:6999a083fb46 | 51 | |
XtaticO | 0:6999a083fb46 | 52 | if (pc.getc()=='4') |
XtaticO | 0:6999a083fb46 | 53 | motor.step(numstep/2,1,step_speed); |
XtaticO | 0:6999a083fb46 | 54 | |
XtaticO | 0:6999a083fb46 | 55 | if (pc.getc()=='5') { |
XtaticO | 0:6999a083fb46 | 56 | printf("Current Speed: %d\n\r", step_speed); |
XtaticO | 0:6999a083fb46 | 57 | printf("New speed: \n\r"); |
XtaticO | 0:6999a083fb46 | 58 | pc.scanf("%d",&step_speed); // sets new speed |
XtaticO | 0:6999a083fb46 | 59 | } |
XtaticO | 0:6999a083fb46 | 60 | } |
XtaticO | 0:6999a083fb46 | 61 | } |
XtaticO | 0:6999a083fb46 | 62 | } |