6
THE LIGHT SENSOR The Light Sensor gives your robot some kind of vision. It can distinguish between light and dark assigning a number between 0 (completely dark) and 100 (maximum light). It can also detect the light intensity of colored surfaces thanks to its Light Emitting Diode, so that it is possible to recognize colors.

THE LIGHT SENSOR

Embed Size (px)

DESCRIPTION

THE LIGHT SENSOR. The Light Sensor gives your robot some kind of vision. It can distinguish between light and dark assigning a number between 0 (completely dark) and 100 (maximum light). - PowerPoint PPT Presentation

Citation preview

Page 1: THE LIGHT SENSOR

THE LIGHT SENSOR

The Light Sensor gives your robot some kind of vision.

It can distinguish between light and dark assigning a number between 0 (completely dark) and 100 (maximum light).

It can also detect the light intensity of colored surfaces thanks to its Light Emitting Diode, so that it is possible to recognize colors.

Page 2: THE LIGHT SENSOR

SENSOR HARDWARE SCHEMATIC

The circuit is not so simple, but it is easy to recognize the LED and the light sensor.

On the right the input port connection is drawn.

The NXT Light Sensor has a range of states between 0 and 100. The lower the number, the darker the reading is.

Page 3: THE LIGHT SENSOR

Connecting the light sensor to the NXT

The input port and the cable have six connections.

The connection can be used to get digital, analog and I2C signals and to supply power to the connected sensor.

Page 4: THE LIGHT SENSOR

What can you do with a light sensor?

You can use the Light Sensor detect the light in a room.

The Light Sensor can be use to follow a black line on a white floor.

You can write a program that makes your robot move on a table without fall down.

Page 5: THE LIGHT SENSOR

NXC, is a high-level programming language for NXT.

NXC has a syntax similar to C language.

Before using a sensor you have to declare its connecting input:

SetSensorLight( port number S1 to S4 );

To read a value and store it in a variable:

x = Sensor(port number);

Programming the Light Sensor with NXC

Page 6: THE LIGHT SENSOR

EXAMPLE PROGRAM

task main()

{

SetSensorLight(S1);

int x;

while(true)

{

ClearScreen();

x=Sensor(S1);

NumOut(10,LCD_LINE1,x);

Wait(200);

}

}