RTOS

Dependencies:   Motor mbed-rtos mbed

Fork of rtos_basic by mbed official

main.cpp

Committer:
tusharb
Date:
2017-04-15
Revision:
12:2de7e289b264
Parent:
11:0309bef74ba8

File content as of revision 12:2de7e289b264:

#include "mbed.h"
#include "rtos.h"
#include "Motor.h"
 

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(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() {
    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);
    
   }
   
     
    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.
          
     
      
    
    
   
    
    
    }
}