light, sound, and ultrasonic sensor. doc lejos api – lejos tutorial –

Post on 02-Jan-2016

217 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Light, Sound, and Ultrasonic Sensor

Doc

• leJOS API– http://lejos.sourceforge.net/nxt/nxj/api/index.html

• leJOS Tutorial– http://lejos.sourceforge.net/nxt/nxj/tutorial/index.htm

MMN Lab.

Light Sensor

• Constructor– LightSensor(SensorPort port) – LightSensor(SensorPort port, boolean floodlig

ht) )

• Method– int readValue()

• Higher numbers indicate more light

– Int readNormalizedValue()

MMN Lab.

Light Sensor cont’d

• Sample program

MMN Lab.

Sound Sensor

• Constructor– SoundSensor(SensorPort port)– SoundSensor(SensorPort port, boolean dba)

• Method– int readValue()– Void setDBA(boolean dba)

MMN Lab.

Sound Sensor cont’d

• Sample program

MMN Lab.

Ultrasonic Sensor

• Constructor– UltrasonicSensor (SensorPort port)

• Method– int getDistance()

MMN Lab.

Ultrasonic Sensor cont’d

• Sample program

MMN Lab.

Lab4

• Scenario– 1. Move forward until light sensor detects the

black area– 2. Use the sound sensor such that the arm

will hit the ball away after a indication– 3. Start to move and stop before bumping

into the wall

• Hint– For the arm, you can use Motor.PORT.Method to do s

ome action

MMN Lab.

top related