fold

Dependencies:   mbed sMotor

Fork of Stepper_4 by Nuno Sarmento

Committer:
zchen311
Date:
Sat Sep 20 14:49:22 2014 +0000
Revision:
1:9393a7e6b1d6
Parent:
0:6999a083fb46
new project;

Who changed what in which revision?

UserRevisionLine numberNew 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
zchen311 1:9393a7e6b1d6 18 DigitalOut myled1(LED1);
zchen311 1:9393a7e6b1d6 19 DigitalOut myled2(LED2);
zchen311 1:9393a7e6b1d6 20 DigitalOut myled3(LED3);
zchen311 1:9393a7e6b1d6 21 DigitalOut myled4(LED4);
XtaticO 0:6999a083fb46 22 int step_speed = 1200 ; // set default motor speed
XtaticO 0:6999a083fb46 23 int numstep = 512 ; // defines full turn of 360 degree
XtaticO 0:6999a083fb46 24 //you might want to calibrate this value according to your motor
XtaticO 0:6999a083fb46 25
XtaticO 0:6999a083fb46 26
zchen311 1:9393a7e6b1d6 27 int main()
zchen311 1:9393a7e6b1d6 28 {
XtaticO 0:6999a083fb46 29
XtaticO 0:6999a083fb46 30 //Credits
XtaticO 0:6999a083fb46 31 printf("4 Phase Stepper Motor v0.1 - Test Program\r\n");
XtaticO 0:6999a083fb46 32 printf("developed by Samuel Matildes\r\n");
XtaticO 0:6999a083fb46 33 printf("\n\r");
XtaticO 0:6999a083fb46 34
XtaticO 0:6999a083fb46 35 // Screen Menu
XtaticO 0:6999a083fb46 36 printf("Default Speed: %d\n\r",step_speed);
XtaticO 0:6999a083fb46 37 printf("1- 360 degree clockwise step\n\r");
XtaticO 0:6999a083fb46 38 printf("2- 360 degree anticlockwise step\n\r");
XtaticO 0:6999a083fb46 39 printf("3- 180 degree clockwise step\n\r");
XtaticO 0:6999a083fb46 40 printf("4- 180 degree anticlockwise step\n\r");
XtaticO 0:6999a083fb46 41 printf("5- Change Speed\n\r");
XtaticO 0:6999a083fb46 42
zchen311 1:9393a7e6b1d6 43 myled1=1;
zchen311 1:9393a7e6b1d6 44 wait(0.2);
zchen311 1:9393a7e6b1d6 45 myled1=0;
zchen311 1:9393a7e6b1d6 46 wait(0.2);
zchen311 1:9393a7e6b1d6 47
XtaticO 0:6999a083fb46 48 while (1) {
XtaticO 0:6999a083fb46 49
zchen311 1:9393a7e6b1d6 50
XtaticO 0:6999a083fb46 51 if (pc.readable()) { // checks for serial
zchen311 1:9393a7e6b1d6 52 printf("ask for input");
zchen311 1:9393a7e6b1d6 53 if (pc.getc()=='1'){
XtaticO 0:6999a083fb46 54 motor.step(numstep,0,step_speed); // number of steps, direction, speed
zchen311 1:9393a7e6b1d6 55 myled1=1;myled2=0;myled3=0;myled4=0;
zchen311 1:9393a7e6b1d6 56 }
zchen311 1:9393a7e6b1d6 57 if (pc.getc()=='2'){
XtaticO 0:6999a083fb46 58 motor.step(numstep,1,step_speed);
zchen311 1:9393a7e6b1d6 59 myled1=0;myled2=1;myled3=0;myled4=0;
zchen311 1:9393a7e6b1d6 60 }
zchen311 1:9393a7e6b1d6 61 if (pc.getc()=='3'){
XtaticO 0:6999a083fb46 62 motor.step(numstep/2,0,step_speed);
zchen311 1:9393a7e6b1d6 63 myled1=0;myled2=0;myled3=1;myled4=0;
zchen311 1:9393a7e6b1d6 64 }
zchen311 1:9393a7e6b1d6 65 if (pc.getc()=='4'){
XtaticO 0:6999a083fb46 66 motor.step(numstep/2,1,step_speed);
zchen311 1:9393a7e6b1d6 67 myled1=0;myled2=0;myled3=0;myled4=1;
zchen311 1:9393a7e6b1d6 68 }
XtaticO 0:6999a083fb46 69 if (pc.getc()=='5') {
XtaticO 0:6999a083fb46 70 printf("Current Speed: %d\n\r", step_speed);
XtaticO 0:6999a083fb46 71 printf("New speed: \n\r");
XtaticO 0:6999a083fb46 72 pc.scanf("%d",&step_speed); // sets new speed
XtaticO 0:6999a083fb46 73 }
XtaticO 0:6999a083fb46 74 }
XtaticO 0:6999a083fb46 75 }
XtaticO 0:6999a083fb46 76 }