A simple tilt sensor-generated interrupt event
Responding to external events in a timely and efficient manner is extremely important in many systems - particularly realtime control systems in areas such as robotics, cars and aeroplanes. Interrupts provide an elegant solution to the problem. This exercise introduces a simple interrupt example and it also demonstrates how interrupt handlers can be built into embedded C programming code.
All the digital pins on the Teensy can be configured as interrupt inputs. In this example the tilt sensor is used to generate an interrupt when a tilt event is detected. Open and upload the sketch IRQTiltV0.ino.
- Tilt the box and notice that the tilt count value jumps to a value in the range 0..100. The count value indicates that the interrupt handler was called multiple times: you may just have expected the count to increase by 1. Why then are there multiple counts?