import josx.platform.rcx.*;

final class Mega implements SensorConstants {
    public static int right;
    public static int left;	
   
   public static void Turning(){ // main line following stuff
   	
   	while(true){
   	if(Sensor.S1.readValue() >= White - 2){ 	
   	Motor.C.forward();
   	if(Sensor.S1.readValue() < White){
   	    Motor.C.stop();  
    }
    } if (Sensor.S1.readValue() <= Line + 2){
   	Motor.C.backward();
   	if(Sensor.S1.readValue() > Line){
   	Motor.C.stop();
    }
    if(Sensor.S1.readValue() != right){
   	Motor.C.stop();
   	}	
   }
  }
} 	
	public static void Initialize(){   // getting set up 
    Sensor.S1.setTypeAndMode(SENSOR_TYPE_LIGHT,SENSOR_MODE_PCT);
    Sensor.S1.activate(); // Turn on the light sensor
    try{Button.RUN.waitForPressAndRelease();} // press the button!
     catch(Exception e){}
    Sound.buzz();
    White = Sensor.S1.readValue(); 
    try{Button.RUN.waitForPressAndRelease();} // press the button!
     catch(Exception e){}
    Sound.buzz();
    Line = Sensor.S1.readValue();
    TextLCD.print("Ready");// lets you know it is ready
    try{Button.RUN.waitForPressAndRelease();} // press the button!
     catch(Exception e){}
    Sound.buzz();
    Motor.A.forward(); // Turn on Motor_A
}
	public static void main(String [] args){ // main task
    
     Motor.C.setPower(2);
     Initialize(); // sensor initialize and stuff   
     Turning(); // Follow the line while(true)(forever!!!)
    }
}     

  		
    

 
   
   		  	
    		