This tutorial makes use of the accelerators in the build-in IMU (Inertial measurement unit) to detect the falling action. When the net acceleration is larger than a certain threshold, the alarm is active until the alarm is switched off by button click.
Step 1. Create a variable to keep track of falling.
Step 2. Initialize the fall variable to false.
Step 3. Create the logic to use the formula.
To check the whether the net acceleration is larger than the falling threshold.
Step 4. Falling is true when the net acceleration is larger than the falling threshold.
Step 5. When falling is true, the alarm is active and the red light is shown. When falling is false, the alarm is inactive and the black light (no light) is shown.
Step 6. Play the tone Low A to alert nearby for 1 beat when falling is true.
Step 7. Set falling to false when Button B is pressed to switch off the alarm.
Step 8. Test the final code.
Step 9. Execute it and see the result.