0

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 by Dani: Formatting fixed

2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by NormR1
0

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 topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.