Line Follower Robot for following a white line on a black background.

Dependencies:   mbed

Line Follower Robot for following a white line on a black background.

main.cpp

Committer:
msarun003
Date:
2014-01-22
Revision:
0:116b193a6a75

File content as of revision 0:116b193a6a75:

/*
#########################################################
##  Program Created by Harshavardan T V & Arun M S     ##
#########################################################
---- harshavardan61@gmail.com & msarun003@gmail.com -----
*/

#include "mbed.h"

DigitalOut led1(LED1);
DigitalOut led2(LED2);
DigitalOut led3(LED3);
DigitalOut led4(LED4);
AnalogIn left(p16); //IR Enable. 
AnalogIn right(p17); //IR Enable. 
DigitalOut left1(p21);
DigitalOut left2(p22);
DigitalOut right1(p23);
DigitalOut right2(p24);


int main() {
    float l,r;
    while (1)
    {
        l=left; //Assign Variable "p" to piezo.
        r=right; //Assign Variable "i" to ir.
    if(l<0.8)
    {
        if(r>0.8)
        {
            led4=1;
            led3=1;
            led1=0;
            led2=0;
            left1=0;
            left2=1;
            right1=1;
            right2=0;                
        }
        else
        {
            led1=1;
            led4=1;
            led2=0;
            led3=0;     
            left1=1;
            left2=0;
            right1=1;
            right2=0;
        }
    }
    else if(l>0.8)
    {
        if(r<0.8)
        {
            led1=1;
            led2=1;                
            led3=0;
            led4=0;
            left1=1;
            left2=0;
            right1=0;
            right2=1;
        }
    else
        {
            led1=1;
            led4=1;
            led2=0;
            led3=0;     
            left1=1;
            left2=0;
            right1=1;
            right2=0;
        }
    }
    else
    {
        led1=1;
        led4=1;
        led2=0;
        led3=0;
        left1=1;
        left2=0;
        right1=1;
        right2=0;
        }
    }
}