Kenan Mahmutović Anes Lučkin

Dependencies:   mbed sMotor

Files at this revision

API Documentation at this revision

Comitter:
tim010
Date:
Thu May 15 18:09:56 2014 +0000
Commit message:
LAB9_GRUPA7_TIM010_ZAD2

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
sMotor.lib Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu May 15 18:09:56 2014 +0000
@@ -0,0 +1,77 @@
+
+#include "mbed.h"
+#include "sMotor.h"
+ 
+ 
+Serial pc(USBTX, USBRX);
+sMotor motor(p9, p10, p11, p13); // creates new stepper motor: IN1, IN2, IN3, IN4
+bool smjer = true;
+int step_speed = 1200 ; // set default motor speed
+int numstep = 512 ; // defines full turn of 360 degree
+//you might want to calibrate this value according to your motor
+
+void kontrolisi_motor ( int x){
+     int broj_koraka = numstep*x/360;
+     motor.step(broj_koraka,smjer,step_speed);
+     
+    }
+void promijeni_smjer() {
+    if(smjer == true){
+    smjer = false;
+    }
+    else smjer = true;
+    
+    }
+void promjena_brzine( int brzina){
+    step_speed = brzina;
+    }
+void pokreni_zaustavi( int x){
+    if(x==4){
+        while(1){
+        motor.step(numstep,smjer,step_speed);
+        }
+        }
+    else motor.step(0,smjer,step_speed);
+    }
+
+int main() {
+   
+   while(1){
+   pc.putc('c');
+   pc.printf("Meni:\n");
+   pc.printf("1.Pomjeranje motora,unesite broj stepeni za koji zelite da rotirate motor.\n");
+   pc.printf("2.Promjena smjera obrtanja motora.\n");
+   pc.printf("3.Promjena brzine kretanja motora.");
+   pc.printf("4.Pokretanje/zaustavljanje motora.");
+   if(pc.readable()){
+       if(pc.getc()=='1'){
+           pc.printf("Unesite broj stepeni za koji zelite da rotirate motor,hvalaaa!");
+           int broj,broj1,broj2;
+           broj=pc.getc();
+           broj1=pc.getc();
+           broj2=pc.getc();
+           int x = (broj-'0')*100 + (broj1- '0')*10 + (broj2 - '0')*1;
+           kontrolisi_motor(x);
+   
+
+       }
+       else if(pc.getc()=='2'){
+           promijeni_smjer();
+           }
+        else if(pc.getc()=='3'){
+           int br,br1,br2;
+           br=pc.getc();
+           br1=pc.getc();
+           br2=pc.getc();
+           int y = (br-'0')*100 + (br1- '0')*10 + (br2 - '0')*1;  
+           promjena_brzine(y);
+           }
+        else if(pc.getc()=='4'){
+            pokreni_zaustavi(4);
+            }
+            
+       
+    }
+
+}
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Thu May 15 18:09:56 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/8a40adfe8776
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sMotor.lib	Thu May 15 18:09:56 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/XtaticO/code/sMotor/#4b3b9e047ce3