light, sound, and ultrasonic sensor. doc lejos api – lejos tutorial –
TRANSCRIPT
![Page 1: Light, Sound, and Ultrasonic Sensor. Doc leJOS API – leJOS Tutorial –](https://reader036.vdocuments.us/reader036/viewer/2022082611/56649eec5503460f94bfd75e/html5/thumbnails/1.jpg)
Light, Sound, and Ultrasonic Sensor
![Page 2: Light, Sound, and Ultrasonic Sensor. Doc leJOS API – leJOS Tutorial –](https://reader036.vdocuments.us/reader036/viewer/2022082611/56649eec5503460f94bfd75e/html5/thumbnails/2.jpg)
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 –](https://reader036.vdocuments.us/reader036/viewer/2022082611/56649eec5503460f94bfd75e/html5/thumbnails/3.jpg)
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 –](https://reader036.vdocuments.us/reader036/viewer/2022082611/56649eec5503460f94bfd75e/html5/thumbnails/4.jpg)
Light Sensor cont’d
• Sample program
MMN Lab.
![Page 5: Light, Sound, and Ultrasonic Sensor. Doc leJOS API – leJOS Tutorial –](https://reader036.vdocuments.us/reader036/viewer/2022082611/56649eec5503460f94bfd75e/html5/thumbnails/5.jpg)
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 –](https://reader036.vdocuments.us/reader036/viewer/2022082611/56649eec5503460f94bfd75e/html5/thumbnails/6.jpg)
Sound Sensor cont’d
• Sample program
MMN Lab.
![Page 7: Light, Sound, and Ultrasonic Sensor. Doc leJOS API – leJOS Tutorial –](https://reader036.vdocuments.us/reader036/viewer/2022082611/56649eec5503460f94bfd75e/html5/thumbnails/7.jpg)
Ultrasonic Sensor
• Constructor– UltrasonicSensor (SensorPort port)
• Method– int getDistance()
MMN Lab.
![Page 8: Light, Sound, and Ultrasonic Sensor. Doc leJOS API – leJOS Tutorial –](https://reader036.vdocuments.us/reader036/viewer/2022082611/56649eec5503460f94bfd75e/html5/thumbnails/8.jpg)
Ultrasonic Sensor cont’d
• Sample program
MMN Lab.
![Page 9: Light, Sound, and Ultrasonic Sensor. Doc leJOS API – leJOS Tutorial –](https://reader036.vdocuments.us/reader036/viewer/2022082611/56649eec5503460f94bfd75e/html5/thumbnails/9.jpg)
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.