Muris Nuhodžić Edis Kunić

Dependencies:   mbed sMotor

Committer:
tim010
Date:
Mon Jun 02 16:45:34 2014 +0000
Revision:
0:0b1211077b9a
Child:
1:d75b1ae184ea
Muris Nuhod?i?; Edis Kuni?

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tim010 0:0b1211077b9a 1 #include "mbed.h"
tim010 0:0b1211077b9a 2 #include "sMotor.h"
tim010 0:0b1211077b9a 3
tim010 0:0b1211077b9a 4
tim010 0:0b1211077b9a 5 Serial pc(USBTX, USBRX);
tim010 0:0b1211077b9a 6 sMotor motor(dp9, dp10, dp11, dp13); // creates new stepper motor: IN1, IN2, IN3, IN4
tim010 0:0b1211077b9a 7
tim010 0:0b1211077b9a 8 int step_speed = 1200 ; // set default motor speed
tim010 0:0b1211077b9a 9 int numstep = 512 ; // defines full turn of 360 degree
tim010 0:0b1211077b9a 10 int direction = 0; //0 for right, 1 for left
tim010 0:0b1211077b9a 11 bool upaljen = false;
tim010 0:0b1211077b9a 12 char c;
tim010 0:0b1211077b9a 13
tim010 0:0b1211077b9a 14 void meni()
tim010 0:0b1211077b9a 15 {
tim010 0:0b1211077b9a 16 pc.printf("Default Speed: %d, press: \n\r",step_speed);
tim010 0:0b1211077b9a 17 pc.printf("1- postavljanje u proizvoljan polozaj\n\r");
tim010 0:0b1211077b9a 18 pc.printf("2- promjena smjera kretanja motora\n\r");
tim010 0:0b1211077b9a 19 pc.printf("3- promjena brzine\n\r");
tim010 0:0b1211077b9a 20 pc.printf("4- pokretanje/zaustavljanje motora\n\r");
tim010 0:0b1211077b9a 21 }
tim010 0:0b1211077b9a 22
tim010 0:0b1211077b9a 23 int main()
tim010 0:0b1211077b9a 24 {
tim010 0:0b1211077b9a 25 meni();
tim010 0:0b1211077b9a 26 while (1) {
tim010 0:0b1211077b9a 27 if (pc.readable()) { // checks for serial
tim010 0:0b1211077b9a 28
tim010 0:0b1211077b9a 29 c=pc.getc();
tim010 0:0b1211077b9a 30 if (c == '1') {
tim010 0:0b1211077b9a 31 /*if(!upaljen) {
tim010 0:0b1211077b9a 32 pc.printf("\n Motor je ugasen, upali motor \n");
tim010 0:0b1211077b9a 33 meni();
tim010 0:0b1211077b9a 34 continue;
tim010 0:0b1211077b9a 35 }*/
tim010 0:0b1211077b9a 36 int ugao;
tim010 0:0b1211077b9a 37 pc.printf("\n Unesi ugao: \n\r");
tim010 0:0b1211077b9a 38 pc.scanf("%d", &ugao);
tim010 0:0b1211077b9a 39 if (ugao > 0 )
tim010 0:0b1211077b9a 40 motor.step(numstep / 360 * (ugao % 360), direction, step_speed); // number of steps, direction, speed
tim010 0:0b1211077b9a 41 else
tim010 0:0b1211077b9a 42 motor.step(numstep / 360 * (ugao % 360), 1 - direction, step_speed); // number of steps, direction, speed
tim010 0:0b1211077b9a 43 meni();if(upaljen) motor.step(numstep, direction, step_speed);
tim010 0:0b1211077b9a 44 }
tim010 0:0b1211077b9a 45
tim010 0:0b1211077b9a 46 if (c =='2') {
tim010 0:0b1211077b9a 47 direction = 1 - direction;
tim010 0:0b1211077b9a 48 pc.printf("\n Smjer je promjenjen\n");
tim010 0:0b1211077b9a 49 meni();if(upaljen) motor.step(numstep, direction, step_speed);
tim010 0:0b1211077b9a 50 }
tim010 0:0b1211077b9a 51 if ( c =='3') {
tim010 0:0b1211077b9a 52 pc.printf("\n trenutna brzina: %d\n\r", step_speed);
tim010 0:0b1211077b9a 53 pc.printf("\n Unesi novu brzinu: \n\r");
tim010 0:0b1211077b9a 54 pc.scanf("%d",&step_speed);
tim010 0:0b1211077b9a 55 if(upaljen) motor.step(numstep, direction, step_speed);
tim010 0:0b1211077b9a 56 meni();if(upaljen) motor.step(numstep, direction, step_speed);
tim010 0:0b1211077b9a 57 }
tim010 0:0b1211077b9a 58
tim010 0:0b1211077b9a 59 if (c =='4') {
tim010 0:0b1211077b9a 60 if(upaljen == false) {
tim010 0:0b1211077b9a 61 upaljen = true;
tim010 0:0b1211077b9a 62 motor.step(numstep, direction, step_speed);
tim010 0:0b1211077b9a 63 pc.printf("\n motor je upaljen \n");
tim010 0:0b1211077b9a 64 } else {
tim010 0:0b1211077b9a 65 upaljen = false;
tim010 0:0b1211077b9a 66 motor.step(numstep, direction, 0);
tim010 0:0b1211077b9a 67 pc.printf("\n motor je ugasen \n");
tim010 0:0b1211077b9a 68 }
tim010 0:0b1211077b9a 69 meni();if(upaljen) motor.step(numstep, direction, step_speed);
tim010 0:0b1211077b9a 70 }
tim010 0:0b1211077b9a 71 }
tim010 0:0b1211077b9a 72 }
tim010 0:0b1211077b9a 73 }
tim010 0:0b1211077b9a 74