![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Predrag Simanić
main.cpp
- Committer:
- tim004
- Date:
- 2014-05-12
- Revision:
- 0:4fd50fc0dbd7
File content as of revision 0:4fd50fc0dbd7:
#include "mbed.h" #include "sMotor.h" Serial pc(USBTX, USBRX); sMotor motor(dp9, dp10, dp11, dp13); // creates new stepper motor: IN1, IN2, IN3, IN4 int step_speed = 1200 ; // set default motor speed int numstep = 512 ; // defines full turn of 360 degree int direction = 0; bool on=true; //you might want to calibrate this value according to your motor int main() { l1: pc.printf("1- Izbor polozaja motora\n\r"); pc.printf("2- Izbor smjera kretanja motora\n\r"); pc.printf("3- Promjena brzine kretanja motora\n\r"); pc.printf("4- Pokretanje/zaustavljanje motora\n\r"); while (1) { if (pc.readable()) { // checks for serial if (pc.getc()=='1'){ if(on) { int angle; pc.printf("Navedite ugao pomjeranja motora: \n\r"); pc.scanf("%d", &angle); if ( angle > 0 ) motor.step(numstep / 360 * (angle % 360), direction, step_speed); else motor.step(numstep / 360 * (angle % 360), 1 - direction, step_speed); } else pc.printf("Motor je zaustavljen. \n\r"); goto l1; }else if (pc.getc()=='2'){ pc.printf("\n Doslo je do promjene smjera. \n\r"); direction=1-direction; goto l1; }else if (pc.getc()=='3'){ pc.printf("Trenutna brzina: %d\n\r", step_speed); pc.printf("Nova brzina: \n\r"); pc.scanf("%d",&step_speed); goto l1; }else if (pc.getc()=='4'){ on=!on; if(on){ pc.printf("Motor je pokrenut.\n\r"); } else{ pc.printf("Motor je zaustavljen. \n\r");} goto l1; } else goto l1; } } }