Muris Nuhodžić Edis Kunić

Dependencies:   mbed sMotor

Files at this revision

API Documentation at this revision

Comitter:
tim010
Date:
Thu Jun 05 17:56:50 2014 +0000
Commit message:
MMuris Nuhod?i? ; Edis Kuni?

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 Jun 05 17:56:50 2014 +0000
@@ -0,0 +1,53 @@
+#include "mbed.h"
+#include "sMotor.h"
+AnalogIn IR(dp4);
+ 
+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/36; // defines full turn of 360 degree
+int direction = 0; //0 for right, 1 for left
+int brojkoraka = 36 ; 
+bool p=true;
+ /*int distanca[]={      10   ,  15 , 20   ,25   , 30   ,   35  , 40  ,    45   ,   50   , 55    ,  60  ,  65 ,  70   ,  75  , 80  ,    85   ,   90};
+ float naponi[]={      0.89, 0.87, 0.81,  0.71 , 0.62 , 0.54,  0.47,  0.43,    0.39 ,  0.34,   0.32,   0.29,   0.28  , 0.25, 0.24,  0.23,            0.21 };*/
+ 
+int provjeri(float n){
+    if(n<0.21)return 200;
+    if(n>0.89)return 1;
+    if(n<=0.89 && n>0.87) return 10;
+    if(n<=0.87 && n>0.81) return 15;
+    if(n<=0.81 && n>0.71) return 20;
+    if(n<=0.71 && n>0.62) return 25;
+    if(n<=0.62 && n>0.54) return 30;
+    if(n<=0.54 && n>0.47) return 35;
+    if(n<=0.47 && n>0.43) return 40;
+    if(n<=0.43 && n>0.39) return 45;
+    if(n<=0.39 && n>0.34) return 50;
+    if(n<=0.34 && n>0.32) return 55;
+    if(n<=0.32 && n>0.29) return 60;
+    if(n<=0.29 && n>0.28) return 65;
+    if(n<=0.28 && n>0.25) return 70;
+    if(n<=0.25 && n>0.24) return 75;
+    if(n<=0.24 && n>0.23) return 80;
+    if(n<=0.23 && n>0.21) return 85;
+    }
+int main() {
+    float a;
+
+int brojac=0;
+    while(1)
+    
+    {
+        motor.step(numstep, direction, step_speed);
+        a = IR;
+        brojac++;
+        if(brojac==36){brojac=0;direction=1-direction;}
+        int b=provjeri(a);
+        pc.printf("%d\n",b );
+        wait(1);
+    }
+    
+    
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Thu Jun 05 17:56:50 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/0b3ab51c8877
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sMotor.lib	Thu Jun 05 17:56:50 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/XtaticO/code/sMotor/#4b3b9e047ce3