void main (void)
{
  initialize();
  wait1Msec(200);
  
  //initialize values
  int pwr = 15;
  int sensorState = -1;
  //determine these values by running the calibration program first
  int threshold1 = 150;
  int threshold2 = 150;
  int delay = 10;
  
  //initialize motors and LED indicators
  setMotor (MOTOR_A, 0);
  setMotor (MOTOR_B, 0);
  LEDnum(0);
  LEDoff(RED_LED);
  LEDoff(GREEN_LED);

  //waits for a button press
  while(getSensor(BUTTON) == 0);
  wait1Msec(100);
  while(getSensor(BUTTON) == 1);
  
  resetTimer(); 
  while(getSensor(BUTTON)== 0 && time100() < 64) { 
  //line follows for 6.4 seconds
    if (sensorState != getSensorState(threshold1, threshold2)) { 
    //only change direction if conditions are different than before. 
      sensorState = getSensorState(threshold1,threshold2);
      if (sensorState == 0) { //go straight
        drive(15, delay);
      } else if (sensorState == 1){
        rightTurn(15,delay);
      } else if (sensorState == 2){
        leftTurn(15, delay);
      } else if (sensorState == 3){
        rightTurn(15, delay);
      }  
    }
  } 
  //hard code exit 2
  rightTurn(pwr,2400);
  drive(pwr,9400);
  leftTurn(pwr,1500);
  drive(pwr,20000);
}
//This code measures how quickly a battery will drain (please start as fully charged)//
task main()
{
	waitForStart();
	nMotorEncoder(Right) = 0;
	nMotorEncoder(Left) = 0;
	wait1Msec(50);

	ClearTimer(T2);

	motor[Right] = speed;
	motor[Left] = -speed;
	AddToDatalog(speedDat, speed);
	wait1Msec(8000);
	//Get up to speed//
	ClearTimer(T1);
	startVolts = nAvgBatteryLevel;
	while(time1(T1) < 10000){
	}
	//Starting encoder ticks per second//
	encSpeed = ((nMotorEncoder(Right) / 10) + (abs(nMotorEncoder(Left)) / 10)) / 2;
	AddToDatalog(encSpeedDat, encSpeed);
	AddToDatalog(startVoltsDat, startVolts);

	newSpeed = encSpeed;

	//Run while at 80% of original speed or greater//
	while(newSpeed >= (encSpeed * 80 / 100)){
		ClearTimer(T1);

		nMotorEncoder(Right) = 0;
		nMotorEncoder(Left) = 0;
		wait1Msec(50);

		while(time1(T1) < 10000){
		}
		//Current encoder ticks per second//
		newSpeed = ((nMotorEncoder(Right) / 10) + (abs(nMotorEncoder(Left)) / 10)) / 2;
		AddToDatalog(newSpeedDat, newSpeed);
		AddToDatalog(newVoltsDat, nAvgBatteryLevel);
	}

  time = time100(T2) / 10;
	AddToDatalog(timeDat, time);
	SaveNxtDatalog();
}