Hi,
I have recently embarked on an adventure into the programming world and am a 'newby' to java. Am trying to get 'my robot' to recgonise the difference between 'blue' and 'red', and execute commands - My program so far is the following - it's not recgonising the colour difference. Help pleeeasssee

import lejos.nxt.*;

public class colourTest

{
  public static void main(String[] args) 
    throws Exception

     {

      LightSensor light = new LightSensor(SensorPort.S1);





            Motor.A.setSpeed(160);  

while(light.readValue() > 475 && < 485)
{


         Motor.A.backward();
         Motor.B.stop();
         Motor.C.stop();
         Thread.sleep(1000);
}

         if(light.readValue() > 375 && < 385)
         {

         Motor.A.forward();
         Motor.B.stop();
         Motor.C.stop();
         Thread.sleep(1000);
         }
         else
         Motor.B.backward();
         Motor.C.backward();
       Thread.sleep(2000);

}

}

Edited 3 Years Ago by Dani: Formatting fixed

Am trying to get 'my robot' to recgonise the difference between 'blue' and 'red'

I don't see any comments in your code describing what it is doing so am unable to help you change it.
Try debugging your code by adding print outs of all the values of the variables to show you where the logic is wrong. For example what is returned by readValue()

This article has been dead for over six months. Start a new discussion instead.