tim004 tim004
/
LV9_Zadatak2_Grupa3_Tim004
Predrag Simanić
Revision 0:4fd50fc0dbd7, committed 2014-05-12
- Comitter:
- tim004
- Date:
- Mon May 12 15:59:56 2014 +0000
- Commit message:
- LV9_Grupa3_Tim004_PAI_Zadatak2
Changed in this revision
diff -r 000000000000 -r 4fd50fc0dbd7 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Mon May 12 15:59:56 2014 +0000 @@ -0,0 +1,64 @@ +#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; + } + } +} \ No newline at end of file
diff -r 000000000000 -r 4fd50fc0dbd7 mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Mon May 12 15:59:56 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/8a40adfe8776 \ No newline at end of file
diff -r 000000000000 -r 4fd50fc0dbd7 sMotor.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sMotor.lib Mon May 12 15:59:56 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/XtaticO/code/sMotor/#4b3b9e047ce3