The Lego Mindstorms NXT is able to play sounds. The
object beeper is associated with this
capacity. However, you can't just assign a value to the
variable beeper, because playing a sound requires
several parameters. You therefore have to call
a method of the beeper object :
beeper.play(200, 3s);
This will play a beep at 200Hz during 3 seconds (beep's frequency must be between 200Hz and 14000Hz).
The parameters of the method may also be the result of operations, or depend on other variables. For example, it is possible to play a sound which frequency depends on the obstacle distance :
mytag:whenever (sonar.val < 100) beeper.play(200+6*sonar,3ms);
This plays beeps with a lower frequency as the obstacle comes closer (under 1 meter).