The light sensor

Test the light sensor and record what values it reads under a variety of conditions. This program reads the amount of ambient light in the room (how light or dark it is)

import lejos.nxt.*;

public class TestLight {
		public static void main(String[] args) throws Exception {
			TouchSensor touch = new TouchSensor(SensorPort.S1);
			LightSensor light = new LightSensor(SensorPort.S2);
			while( ! touch.isPressed() ){// loop until touch sensor bumps
				int lightAmt = light.readValue();
				LCD.clear();
				LCD.drawInt( lightAmt, 3, 3);// display the amount of light
				LCD.refresh();
				Thread.sleep(250); // wait a quarter of a second
			}
		}
}
Condition Results
In the brightest area of the room  
Iin the darkest area of the room  
try pointing at some different colors, do they make any difference?
________
________
________
 

you think of some other conditions and record your results:

 

 

change the program to say:
LightSensor light = new LightSensor(SensorPort.S2, false);
instead of
LightSensor light = new LightSensor(SensorPort.S2);
run it again, how is the program different?

 
linePoint the light down at the ground, can the robot tell if it is on top of a dark line or not? What values does it read when over black? _____, white? ______
Create a program to follow the line (algorithm: start on the dark line, in a loop keep going until the touch sensor is pressed: {move a little bit forward, if the robot is not on the dark line try turning a little bit until you can see the line again}) TOP GRADE: make it follow this line too.