Example #1
0
//------------------------------------------------------------------------------
void RoverIRSensors::takeReadings()
{
    mLastFrontLeftReading = readIRSensor( mFrontLeftLedPin, mFrontLeftSensorPin );
    mLastFrontRightReading = readIRSensor( mFrontRightLedPin, mFrontRightSensorPin );
    mLastRearLeftReading = readIRSensor( mRearLeftLedPin, mRearLeftSensorPin );
    mLastRearRightReading = readIRSensor( mRearRightLedPin, mRearRightSensorPin );
}
void moveToLocation(int newPosition)
{
	if(newPosition != currentPosition){
		startMotor();
		Delay10KTCYx(7);
		while(!readIRSensor());
		stopMotor();
		
		//Track the current location of the plant
		currentPosition++;	
		
		if(currentPosition == 3){
			currentPosition = 0;	
		}	
	
		//recursive call to move the the next position if this is not the required state	
		if(newPosition != currentPosition){
			moveToLocation(newPosition);
		}
	}
}