Play tones on speaker in NXT brick
Use this block to play tones from the speaker in the NXT brick.
To play a tone, send an audible value to the block input for frequency (Freq) and/or volume (Vol). To stop playing a tone, send an inaudible value, such as zero, to either block input. The range of audible frequencies that the speaker can produce is approximately 32 to 13000 Hz. The speaker volume ranges from 0 to 100 (softest to loudest).
To set either the frequency or volume to a static value, disable one of the block inputs using the Input mode parameter, and then enter the static value for the equivalent parameter on the block mask. For example, if the speaker is only going to play a single frequency, set Input mode to Volume only, and then set the Frequency (Hz) parameter to 440.
This block automatically converts the data type of the data it receives. You do not need to perform data-type conversion on the input signals.
If you run a simulation of a model that contains this block without the target hardware, this block does nothing. See Block Produces Zeros or Does Nothing in Simulation.
Open the legonxtlib block library and copy the blocks shown to a new model.
Double click the Speaker block. In the block mask that opens, change the Input mode parameter to Volume only, and enter a value of 440 for the Frequency (Hz) parameter. Then click OK.
Connect the Button block to the Gain block, and the Gain block to the Speaker block, as shown.
Double click the Gain block. In the block mask that opens, set the Gain parameter to 50. When you press the orange button on the NXT brick, the Gain block will send a value of 50 to the volume input on the Speaker block.
Prepare and run the model on the NXT brick.
When you press the orange button, the speaker emits a 440 Hz tone.
Enable or disable the block inputs:
Frequency and volume — Enables both Freq and Vol.
Volume only — Enables the Vol block input, disables the Freq block input, and enables the Frequency (Hz) parameter on the block mask.
Frequency only — Enables the Freq block input, disables the Vol block input, and enables the Volume (0 - 100) parameter on the block mask.
Enter the frequency of the tone the speaker emits. When the Input mode parameter is configured to enable a Freq input, this parameter is not available.
Set the volume of the tone the speaker emits. When the Input mode parameter is configured to enable a Vol input, this parameter is not available.
Play a continuous tone or an intermittent tone (beeps). If this value is equal to or greater than the sample time of the source block, the speaker emits a continuous tone. If this value is shorter than the sample time of the source block, the speaker emits an intermittent tone at each sample period. For example, in the preceding ex_battery_voltage_alarm model, if the sample time for the battery is 0.1 seconds, and the speaker duration is 100 milliseconds (0.1 seconds), the speaker plays a continuous tone. If you change the speaker duration to 50 milliseconds (half the battery sample time), the speaker emits a beep every 0.1 seconds.