Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp
- Committer:
- Privias
- Date:
- 2014-07-17
- Revision:
- 0:086810854173
File content as of revision 0:086810854173:
#include "mbed.h" PwmOut Right1(p24); PwmOut Right(p23); PwmOut Left1(p22); PwmOut Left(p21); AnalogIn ainL1(p17) ; //Left Sencer IN AnalogIn ainR1(p18) ; //Right Sencor IN AnalogIn ain(p16); //Sensor Serial pc(USBTX,USBRX) ; int main(){ wait_ms(2000); pc.baud ( 115200 ) ; Right.period(0.020); Right1.period(0.020); Left.period(0.020); Left1.period(0.020); double p ; while(1){ double L1 = ainL1.read() ; double adVL = L1*100 ; double R1 = ainR1.read() ; double adVR = R1*100 ; double ai=ain*100; double t=1.0; if(ai>60.0){ p=0.001; double t=0; } if(ai>58.0 && ai<=60.0){ p=0.005; } if(ai>57.0 && ai<=58.0){ p=0.006; } if(ai>55.0 && ai<=57.0){ p=0.007; } if(ai>=50.0 && ai<=55.0){ p=0.008; } if(ai<50.0 && ai<=30.0){ p=0.010; } if(ai<30.0){ p=0.018; } //Speed double p1=0.007; //double p=0.007; //speed //Line Found double adRR= 1.0 ; double adLL= 2.1; if(t==0){ Right.pulsewidth(0.004); Left.pulsewidth(0.004); Right1.pulsewidth(0.004); Left1.pulsewidth(0.004); } if(adVR <adRR && adVL> adLL){ //if Right sensor found Brack Line Right.pulsewidth(0); Left1.pulsewidth(0); Right1.pulsewidth(p1); //Left Motor on AND Roght Motor off Left.pulsewidth(p1); } if(adVL<adLL && adVR>adRR){ //if Left sensor found Brack Line Right1.pulsewidth(0); Left.pulsewidth(0); Left1.pulsewidth(p1); //Left Motor off AND Roght Motor on Right.pulsewidth(p1); } if(adVR>adRR && adVL>adLL){ // if Vihicle in White Line Right1.pulsewidth(0); Left1.pulsewidth(0); Right.pulsewidth(p); Left.pulsewidth(p); //Go Strait } if(adVR<adRR && adVL<adLL){ // if Vihicle in Black Line Right.pulsewidth(0); Left.pulsewidth(0); Right1.pulsewidth(p); Left1.pulsewidth(p); //Go Back wait_ms(50); } pc.printf( "L-Sensor = %4.2f R-Sensor = %4.2f \r\n ", adVL, adVR ) ; }//while }//main