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

9
Light, Sound, and Ultrasonic Sensor

Upload: paulina-whitehead

Post on 02-Jan-2016

217 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Light, Sound, and Ultrasonic Sensor. Doc leJOS API – leJOS Tutorial –

Light, Sound, and Ultrasonic Sensor

Page 2: Light, Sound, and Ultrasonic Sensor. Doc leJOS API – leJOS Tutorial –

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.

Page 3: Light, Sound, and Ultrasonic Sensor. Doc leJOS API – leJOS Tutorial –

Light Sensor

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

ht) )

• Method– int readValue()

• Higher numbers indicate more light

– Int readNormalizedValue()

MMN Lab.

Page 4: Light, Sound, and Ultrasonic Sensor. Doc leJOS API – leJOS Tutorial –

Light Sensor cont’d

• Sample program

MMN Lab.

Page 5: Light, Sound, and Ultrasonic Sensor. Doc leJOS API – leJOS Tutorial –

Sound Sensor

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

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

MMN Lab.

Page 6: Light, Sound, and Ultrasonic Sensor. Doc leJOS API – leJOS Tutorial –

Sound Sensor cont’d

• Sample program

MMN Lab.

Page 7: Light, Sound, and Ultrasonic Sensor. Doc leJOS API – leJOS Tutorial –

Ultrasonic Sensor

• Constructor– UltrasonicSensor (SensorPort port)

• Method– int getDistance()

MMN Lab.

Page 8: Light, Sound, and Ultrasonic Sensor. Doc leJOS API – leJOS Tutorial –

Ultrasonic Sensor cont’d

• Sample program

MMN Lab.

Page 9: Light, Sound, and Ultrasonic Sensor. Doc leJOS API – leJOS Tutorial –

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.