Modify the Play Sound app you created to also play a sound when you shake the phone. To do this, first add an
AccelerometerSensor
component, found under the Sensors section of the component designer. Then in the blocks editor, add a Shaking event handler, found in theAccelerometerSensor
drawer. Finally, add aPlay
function call, found in theSound
drawer, to the event handler. Test your changes by shaking the phone.As you shake the phone, the sound will sound strange, as if it is echoing. That is because the accelerometer sensor is triggering the shaking event many times a second, so the sounds are overlapping. If you look at the
Sound
component in the Designer, you will see a property calledMinimum interval
. That determines how close together successive sounds can start. It is currently set at a half-second (500 milliseconds), which is probably less than the duration of a single sound. By playing with the minimum interval, you can change how much the sounds overlap. Set the minimum interval so that the sound do not overlap at all.