// wall follower
// code by Martyn_Boogaarts
// sensor and motors
#define EYE         SENSOR_2 
// light sensor for getting markings on the floor of the maze
#define WALL        SENSOR_3
// wall follow sensor if open(0) then seperate from the wall
#define FRONT       SENSOR_1
// to see if I bump into something, or in a dead end 
// motors
#define LEFT           OUT_A
#define RIGHT          OUT_C

task wallfollow()
{
    SetSensor(WALL, SENSOR_TOUCH);

    OnFwd(LEFT+RIGHT);
    while(true)
    {
        if (FRONT !=1 )
        {
            Off(LEFT+RIGHT);
            Wait(20); // wait and see if it was an other robot
            if (FRONT !=1 )
            {
//            still something infront of the robot, so backup a little
            OnRev(LEFT+RIGHT);
            Wait(10);
            OnFwd(LEFT);
            Wait(20);   // time needed to turn
            // some deadrecon code .....
            OnFwd(LEFT+RIGHT);
            }
            else
            {
            // continue
            OnFwd(LEFT+RIGHT);
            }
        }
        else if (WALL == 1)
        {

            Off(LEFT);
            OnFwd(RIGHT);
            OnRev(LEFT);
            
        }
        else
        {
            OnFwd(LEFT+RIGHT);
            Wait(4);
        }
    }
} // end wallfollow

task detectfloor()
{
SetSensor(EYE, SENSOR_LIGHT);
 while(true)
    {
    if (EYE > 75)
    	{
    	// do something you found a marking
    	}
    }


} // end detectfloor

task main()
{
start wallfollow;
start detectfloor;
}
