Sound the alarm past 20°
Arduino C++The starter reads the tilt and prints it, but nothing warns anyone. When the roll is past 20° either way, set D13 HIGH and play a 2 kHz tone on the buzzer (D8); otherwise D13 LOW and noTone(). The board is level at first, tipped 35° at 2 s, back to -10° at 3.5 s and tipped -40° at 5 s.
Checks
- Not run yetRuns
- Not run yetLevel: D13 LOW
- Not run yetTipped 35°: D13 HIGH
- Not run yetTipped 35°: the buzzer sounds at about 2 kHz
- Not run yetBack to -10°: D13 LOW again
- Not run yetTipped -40°: D13 HIGH
- Not run yetTipped -40°: the buzzer sounds
Hints
- abs(roll) > 20 catches both directions.
- tone(BUZZER, 2000) keeps playing until noTone(BUZZER).
- digitalWrite(13, alarm ? HIGH : LOW); sets the LED in one line.