ETF-PAI- Kunić Edis, Nuhodžić Muris

Dependencies:   mbed sMotor

Revision:
0:c72c81cd99ba
Child:
1:888aeafa6c13
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Mon Jun 09 12:32:12 2014 +0000
@@ -0,0 +1,47 @@
+#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
+ /* distanca {   10 ,   15 ,   20 ,   25 ,   30 ,   35 ,   40 ,   45 ,   50 ,    55 ,   60 ,   65 ,   70 ,   75 ,   80 ,   85 ,   90 }
+    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