accelerometer adxl 335 and motor direction

Dependencies:   DcMotorDirectDrive Motor mbed adxl335_motor_direction

Dependents:   adxl335_motor_direction

Revision:
0:c2c24acf6b77
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu Apr 13 10:54:06 2017 +0000
@@ -0,0 +1,63 @@
+#include "mbed.h"
+#include "Motor.h"
+ 
+AnalogIn inputx(p20); // input pins 20,19,18 for x,y,z axis respectively.
+AnalogIn inputy(p19);
+
+Motor m1(p23,p5,p6); // pwm, fwd, rev
+Motor m2(p22,p11,p12); // pwm,fwd,rev
+
+Serial pc(USBTX,USBRX);  //Serial class for transmission of serial data
+ 
+int main() 
+{
+pc.baud(9600);   // fixing a constant baud rate of 9600 bps at which mbed will interact with computer
+float cal_x,cal_y;  //caliberation variables
+int x,y; // variables for x,y,z axes
+int i=100;
+while(i--)      //small timed loop to caliberate the accelerometer with currentl position of the accelerometer
+{
+cal_x=inputx*100;
+cal_y=inputy*100;
+
+}
+while(1)
+    {  
+        x=4*(cal_x - inputx*100);
+        y=4*(cal_y - inputy*100);
+ 
+  
+    y=(y-30);
+      pc.printf("x=%d,y=%d *",x,y);
+      pc.printf("\n");
+     
+    if(x <= 0 && y <=0)
+   {
+       for (float s= -1.0; s > -1000.0 ; s += -0.01)
+      
+       m1.speed(s); // anticlockwise
+      for (float s= -1.0; s > -1000.0 ; s += -0.01)  
+       m2.speed(s);
+    
+   }
+   
+     
+    else if (x>=0 && y>=0)
+   { for (float s= 1.0; s < 1000.0 ; s += 0.01)
+       m1.speed(s); // clockwise
+      for (float s= 1.0; s < 1000.0 ; s += 0.01)
+      m2.speed(s);                                                                                                 
+  
+   }
+    
+    else
+    {
+        m1.speed(0);
+        }
+       
+       
+     
+        //passing the caliberated x,y,z values to the computer.
+        }  
+       
+}
\ No newline at end of file