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.
Fork of mbed-os-example-mbed5-blinky by
main.cpp@14:0357b4ab5699, 2018-03-26 (annotated)
- Committer:
- Jsquiroga
- Date:
- Mon Mar 26 23:37:33 2018 +0000
- Revision:
- 14:0357b4ab5699
- Parent:
- 8:bb09890333fe
Blinky led example using interruptions.; Shows an easy way to turn on/off a led using interruptions.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Jsquiroga | 14:0357b4ab5699 | 1 | #include "mbed.h" |
Jonathan Austin |
0:2757d7abb7d9 | 2 | |
Jsquiroga | 14:0357b4ab5699 | 3 | |
Jsquiroga | 14:0357b4ab5699 | 4 | //Define outputs |
Jsquiroga | 14:0357b4ab5699 | 5 | |
Jsquiroga | 14:0357b4ab5699 | 6 | DigitalOut blue(LED3); |
Jsquiroga | 14:0357b4ab5699 | 7 | |
Jsquiroga | 14:0357b4ab5699 | 8 | |
Jsquiroga | 14:0357b4ab5699 | 9 | //Define interrupt inputs |
Jsquiroga | 14:0357b4ab5699 | 10 | |
Jsquiroga | 14:0357b4ab5699 | 11 | InterruptIn button(SW2); //interrupcion para el boton 2 |
Jsquiroga | 14:0357b4ab5699 | 12 | |
Jsquiroga | 14:0357b4ab5699 | 13 | |
Jsquiroga | 14:0357b4ab5699 | 14 | void BlinkLed (){ |
Jsquiroga | 14:0357b4ab5699 | 15 | blue=!blue; |
Jsquiroga | 14:0357b4ab5699 | 16 | } |
Jonathan Austin |
0:2757d7abb7d9 | 17 | |
Jsquiroga | 14:0357b4ab5699 | 18 | |
Jsquiroga | 14:0357b4ab5699 | 19 | int main() |
Jsquiroga | 14:0357b4ab5699 | 20 | { |
Jsquiroga | 14:0357b4ab5699 | 21 | __enable_irq(); //Enable Interrupts |
Jsquiroga | 14:0357b4ab5699 | 22 | |
Jsquiroga | 14:0357b4ab5699 | 23 | blue=0; //initialize output |
Jsquiroga | 14:0357b4ab5699 | 24 | |
Jsquiroga | 14:0357b4ab5699 | 25 | button.rise(&blinkLed); //The ISR activates with rising edge of button and activate the function. |
Jsquiroga | 14:0357b4ab5699 | 26 | |
Jsquiroga | 14:0357b4ab5699 | 27 | |
Jsquiroga | 14:0357b4ab5699 | 28 | while(1) |
Jsquiroga | 14:0357b4ab5699 | 29 | { |
Jsquiroga | 14:0357b4ab5699 | 30 | // Write your code |
Jsquiroga | 14:0357b4ab5699 | 31 | |
Jonathan Austin |
0:2757d7abb7d9 | 32 | } |
Jsquiroga | 14:0357b4ab5699 | 33 | } |