Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
Fork of ButtonInterrupt by
main.cpp@0:df23bf5767ec, 2017-08-12 (annotated)
- Committer:
- rossatmsoe
- Date:
- Sat Aug 12 20:13:26 2017 +0000
- Revision:
- 0:df23bf5767ec
Initial version of ButtonInterrupt program for MSOE EE2905
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| rossatmsoe | 0:df23bf5767ec | 1 | #include "mbed.h" |
| rossatmsoe | 0:df23bf5767ec | 2 | |
| rossatmsoe | 0:df23bf5767ec | 3 | // Declare that the USER_BUTTON will trigger an external interrupt mybutton |
| rossatmsoe | 0:df23bf5767ec | 4 | InterruptIn mybutton(USER_BUTTON); |
| rossatmsoe | 0:df23bf5767ec | 5 | |
| rossatmsoe | 0:df23bf5767ec | 6 | DigitalOut myled(LED1); |
| rossatmsoe | 0:df23bf5767ec | 7 | |
| rossatmsoe | 0:df23bf5767ec | 8 | // Function prototypes |
| rossatmsoe | 0:df23bf5767ec | 9 | void pressed(); |
| rossatmsoe | 0:df23bf5767ec | 10 | void released(); |
| rossatmsoe | 0:df23bf5767ec | 11 | |
| rossatmsoe | 0:df23bf5767ec | 12 | int main() |
| rossatmsoe | 0:df23bf5767ec | 13 | { |
| rossatmsoe | 0:df23bf5767ec | 14 | // Define the behavior of the interrupt on rising and falling edges |
| rossatmsoe | 0:df23bf5767ec | 15 | mybutton.fall(&pressed); |
| rossatmsoe | 0:df23bf5767ec | 16 | mybutton.rise(&released); |
| rossatmsoe | 0:df23bf5767ec | 17 | |
| rossatmsoe | 0:df23bf5767ec | 18 | // do nothing; the interrupt servicing functions do all the work |
| rossatmsoe | 0:df23bf5767ec | 19 | while(1) { |
| rossatmsoe | 0:df23bf5767ec | 20 | wait(1); |
| rossatmsoe | 0:df23bf5767ec | 21 | } |
| rossatmsoe | 0:df23bf5767ec | 22 | |
| rossatmsoe | 0:df23bf5767ec | 23 | } |
| rossatmsoe | 0:df23bf5767ec | 24 | |
| rossatmsoe | 0:df23bf5767ec | 25 | void pressed() { // short flash when pressed |
| rossatmsoe | 0:df23bf5767ec | 26 | myled = 1; |
| rossatmsoe | 0:df23bf5767ec | 27 | wait(0.2); |
| rossatmsoe | 0:df23bf5767ec | 28 | myled = 0; |
| rossatmsoe | 0:df23bf5767ec | 29 | } |
| rossatmsoe | 0:df23bf5767ec | 30 | |
| rossatmsoe | 0:df23bf5767ec | 31 | void released() { // long flash when released |
| rossatmsoe | 0:df23bf5767ec | 32 | myled = 1; |
| rossatmsoe | 0:df23bf5767ec | 33 | wait(1); |
| rossatmsoe | 0:df23bf5767ec | 34 | myled = 0; |
| rossatmsoe | 0:df23bf5767ec | 35 | } |
