MOTOR PASO A PASO

Dependencies:   mbed sMotor

Fork of Stepper_4 by Nuno Sarmento

Committer:
pablolopez89
Date:
Tue Apr 10 00:12:59 2018 +0000
Revision:
1:be5a5f38621d
Parent:
0:6999a083fb46
MOTOR PASO A PASO

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);
pablolopez89 1:be5a5f38621d 17 sMotor motor(PC_7, PB_6, PA_7, PA_6); // 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
pablolopez89 1:be5a5f38621d 27 pc.printf("4 Phase Stepper Motor v0.1 - Test Program\r\n");
pablolopez89 1:be5a5f38621d 28 pc.printf("developed by Samuel Matildes\r\n");
pablolopez89 1:be5a5f38621d 29 pc.printf("\n\r");
XtaticO 0:6999a083fb46 30
XtaticO 0:6999a083fb46 31 // Screen Menu
pablolopez89 1:be5a5f38621d 32 pc.printf("Default Speed: %d\n\r",step_speed);
pablolopez89 1:be5a5f38621d 33 pc.printf("1- 360 degree clockwise step\n\r");
pablolopez89 1:be5a5f38621d 34 pc.printf("2- 360 degree anticlockwise step\n\r");
pablolopez89 1:be5a5f38621d 35 pc.printf("3- 180 degree clockwise step\n\r");
pablolopez89 1:be5a5f38621d 36 pc.printf("4- 180 degree anticlockwise step\n\r");
pablolopez89 1:be5a5f38621d 37 pc.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') {
pablolopez89 1:be5a5f38621d 56 pc.printf("Current Speed: %d\n\r", step_speed);
pablolopez89 1:be5a5f38621d 57 pc.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 }