tim008 tim008
/
zad2-grupa7-tim008
Emrah Dautbegović Edis Kunić
Revision 0:d1b1742b324c, committed 2014-05-15
- Comitter:
- tim008
- Date:
- Thu May 15 18:13:30 2014 +0000
- Commit message:
- Lv9-Pai-grupa7-tim008-zad2
Changed in this revision
diff -r 000000000000 -r d1b1742b324c main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Thu May 15 18:13:30 2014 +0000 @@ -0,0 +1,89 @@ +#include "mbed.h" +#include "sMotor.h" +//motor.step(numstep,smjer,speed); +int smjer = 0; +bool radi = true; +Serial pc(USBTX, USBRX); +sMotor motor(dp9, dp10, dp11, dp13); // creates new stepper motor: IN1, IN2, IN3, IN4 +int speed = 900 ; // set default motor speed +float numstep = 512 ; //broj koraka potrebnih da motor napravi ugao od 360 stepeni + +void objasni() { +pc.printf("\n NAREDBE: "); +pc.printf("\nA-postavi osovinu motora(0-360) stepeni"); +pc.printf("\nB-promijeni smjer kretanja motora"); +pc.printf("\nC-promijeni brzinu kretanja motora"); +pc.printf("\nD-pokreni/zaustavi motor"); +} + +char ocitajNaredbu() { +char naredba; +pc.printf("\nUnesi naredbu: "); +naredba=pc.getc(); +while(naredba != 'A' && naredba != 'B' && naredba != 'C' && naredba != 'D') { +pc.printf("\nUnesi naredbu: "); +naredba=pc.getc(); +} +return naredba; +} + +void postaviUgaoOsovine() { + int ugao; + pc.printf("\nUnesi ugao(stepeni): "); + pc.scanf("%d", &ugao); + numstep = (int)((512./360.)*(ugao%360)); +if(ugao>0){ + if(radi==true) + motor.step(numstep,smjer,speed); + } + else { + smjer = 1-smjer; + if(radi==true) + motor.step(numstep,smjer,speed); + } +} + +void promijeniSmjer() { +smjer = 1-smjer; +if(radi==true) +motor.step(numstep,smjer,speed); +} + +void promijeniBrzinu() { +pc.printf("\nUnesi brzinu: "); +pc.scanf("%d", &speed); +if(radi==true) +motor.step(numstep,smjer,speed); +} + +void pali_gasi() { +if(radi) pc.printf("\nMotor je upaljen i krece se brzinom %d.", speed); +else pc.printf("\nMotor je ugasen."); +} + +void startOrStop() { +if(radi == true) { +radi = false; +speed = 0; +} +else { +radi = true; +speed = 900; +} +motor.step(numstep,smjer,speed); +} + +int main() { + char naredba; + motor.step(numstep,smjer,speed); + while(1) { + objasni(); + pali_gasi(); + naredba = ocitajNaredbu(); + if(naredba == 'A') postaviUgaoOsovine(); + else if(naredba == 'B') promijeniSmjer(); + else if(naredba == 'C') promijeniBrzinu(); + else if(naredba == 'D') startOrStop(); + wait(1); + } +} \ No newline at end of file
diff -r 000000000000 -r d1b1742b324c mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Thu May 15 18:13:30 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 d1b1742b324c sMotor.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sMotor.lib Thu May 15 18:13:30 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/XtaticO/code/sMotor/#4b3b9e047ce3