RTOS

Dependencies:   Motor mbed-rtos mbed

Fork of rtos_basic by mbed official

Files at this revision

API Documentation at this revision

Comitter:
tusharb
Date:
Sat Apr 15 16:02:26 2017 +0000
Parent:
11:0309bef74ba8
Commit message:
ACCELEROMETER DC MOTOR USING RTOS CONCEPT

Changed in this revision

Motor.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Motor.lib	Sat Apr 15 16:02:26 2017 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/simon/code/Motor/#f265e441bcd9
--- a/main.cpp	Wed Feb 15 14:04:02 2017 -0600
+++ b/main.cpp	Sat Apr 15 16:02:26 2017 +0000
@@ -1,22 +1,100 @@
 #include "mbed.h"
 #include "rtos.h"
+#include "Motor.h"
  
-DigitalOut led1(LED1);
+
 DigitalOut led2(LED2);
+DigitalOut led3(LED3);
+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
+Serial pc(USBTX,USBRX); 
+
+
 Thread thread;
  
 void led2_thread() {
     while (true) {
+         for (float s= -1.0; s > -1000.0 ; s += -0.01)
+             m1.speed(s); // anticlockwise
+        
         led2 = !led2;
-        Thread::wait(1000);
+        Thread::wait(10000);
     }
 }
+
+void led3_thread() {
+    while (true) {
+         for (float s= 1.0; s < 1000.0 ; s += 0.01)
+       m1.speed(s); // clockwise
+        
+        led3 = !led3;
+        Thread::wait(10000);
+    }
+}
+
+
+
+
+
+
+
+
  
 int main() {
-    thread.start(led2_thread);
+    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)
+   {
+       thread.start(led2_thread);
     
-    while (true) {
-        led1 = !led1;
-        Thread::wait(500);
+   }
+   
+     
+    else if (x>=0 && y>=0)
+   { 
+      thread.start(led3_thread);                                                                                              
+  
+   }
+    
+    else if (x>=0 && y<=0)
+    {
+        thread.start(led2_thread);
+        }
+       
+       else if(x<=0 && y>=0)
+       {
+           
+           thread.start(led3_thread);       
+           }
+           
+     
+        //passing the caliberated x,y,z values to the computer.
+          
+     
+      
+    
+    
+   
+    
+    
     }
 }