DroidScript wiki

(was AndroidScript) unofficial documentation by the community

User Tools

Site Tools


built_in:nxt_readsoundsensor

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

built_in:nxt_readsoundsensor [2015/03/09 16:16] (current)
octazid created
Line 1: Line 1:
 +====== ReadSoundSensor ======
  
 +The **ReadSoundSensor** function reads the sound pressure level (loudness) of the sound currently being '​heard'​ by the sound sensor (Note: Sound sensors are not included with the standard NXT kit)
 +
 +The **input** parameter should be an NXT input port number between 1 and 4 (which the sound sensor is plugged into).
 +
 +The **mode** parameter should be one of the following values: **"​DB"​** or **"​DbA"​** depending if you want the returned value in standard Decibels or A-weighted Decibels.
 +<​code>​spl = nxt.ReadSoundSensor( input, mode );</​code>​
 +
 +====Example - Read sound level on port 1====
 +<code javascript>​
 +function OnStart()
 +{
 +  nxt = app.CreateNxt();​
 +  app.SetMenu( "​Connect,​Sound Level" );
 +}
 +
 +function OnMenu( name )
 +{
 +  if( name=="​Connect"​ )
 +    nxt.ShowDevices();​
 +
 +  else if( name=="​Sound Level" )
 +  {
 +    spl = nxt.ReadSoundSensor( 1, "​dB"​ );
 +    app.ShowPopup( spl );
 +  }
 +}
 +</​code>​
built_in/nxt_readsoundsensor.txt ยท Last modified: 2015/03/09 16:16 by octazid