Class: SoundSensor
Constant Summary
Constants inherited from Sensor
Instance Attribute Summary
Attributes inherited from Brick
Instance Method Summary collapse
-
#get_sound_level ⇒ Object
Get the current sound level as a float from 0 to 1.0.
-
#initialize(nxt, port = NXTComm::SENSOR_2) ⇒ SoundSensor
constructor
A new instance of SoundSensor.
-
#use_adjusted_mode ⇒ Object
Sound level measurement is adjusted to match the psychoacoustic properties of human hearing.
-
#use_unadjusted_mode ⇒ Object
Sound level measurement is NOT adjusted to match the psychoacoustic properties of human hearing.
Methods inherited from Sensor
#name, #off, #read_data, #set_input_mode, #wait_for_event
Constructor Details
#initialize(nxt, port = NXTComm::SENSOR_2) ⇒ SoundSensor
Returns a new instance of SoundSensor.
23 24 25 26 |
# File 'lib/sensors/sound_sensor.rb', line 23 def initialize(nxt, port = NXTComm::SENSOR_2) super(nxt, port) use_adjusted_mode end |
Instance Method Details
#get_sound_level ⇒ Object
Get the current sound level as a float from 0 to 1.0. 1.0 is maximum, 0 is minimum.
30 31 32 33 |
# File 'lib/sensors/sound_sensor.rb', line 30 def get_sound_level # TODO: should probably do some basic calibration here... read_data[:value_normal] / 1023.to_f end |
#use_adjusted_mode ⇒ Object
Sound level measurement is adjusted to match the psychoacoustic properties of human hearing. This is on by default.
44 45 46 |
# File 'lib/sensors/sound_sensor.rb', line 44 def use_adjusted_mode set_input_mode(NXTComm::SOUND_DBA, NXTComm::RAWMODE) end |
#use_unadjusted_mode ⇒ Object
Sound level measurement is NOT adjusted to match the psychoacoustic properties of human hearing. Sounds that may not be loud to the human ear may show up as loud and vice versa.
38 39 40 |
# File 'lib/sensors/sound_sensor.rb', line 38 def use_unadjusted_mode set_input_mode(NXTComm::SOUND_DB, NXTComm::RAWMODE) end |