Selvakumar Samuel
/
Board1Prg2
Program for Interrupt button
main.cpp@0:bcf6fcde4f32, 2018-03-28 (annotated)
- Committer:
- selvakumararm
- Date:
- Wed Mar 28 07:33:30 2018 +0000
- Revision:
- 0:bcf6fcde4f32
Testing 2
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
selvakumararm | 0:bcf6fcde4f32 | 1 | #include "mbed.h" |
selvakumararm | 0:bcf6fcde4f32 | 2 | |
selvakumararm | 0:bcf6fcde4f32 | 3 | DigitalOut myled(LED1); |
selvakumararm | 0:bcf6fcde4f32 | 4 | //DigitalIn button1(USER_BUTTON); |
selvakumararm | 0:bcf6fcde4f32 | 5 | InterruptIn button1(USER_BUTTON); |
selvakumararm | 0:bcf6fcde4f32 | 6 | |
selvakumararm | 0:bcf6fcde4f32 | 7 | bool active = false; |
selvakumararm | 0:bcf6fcde4f32 | 8 | |
selvakumararm | 0:bcf6fcde4f32 | 9 | void BUTTON_ISR(){ |
selvakumararm | 0:bcf6fcde4f32 | 10 | active = !active; |
selvakumararm | 0:bcf6fcde4f32 | 11 | } |
selvakumararm | 0:bcf6fcde4f32 | 12 | |
selvakumararm | 0:bcf6fcde4f32 | 13 | int main() { |
selvakumararm | 0:bcf6fcde4f32 | 14 | // Set up |
selvakumararm | 0:bcf6fcde4f32 | 15 | button1.mode(PullUp); |
selvakumararm | 0:bcf6fcde4f32 | 16 | button1.fall(&BUTTON_ISR); |
selvakumararm | 0:bcf6fcde4f32 | 17 | |
selvakumararm | 0:bcf6fcde4f32 | 18 | while(1) { |
selvakumararm | 0:bcf6fcde4f32 | 19 | if(active == true){ |
selvakumararm | 0:bcf6fcde4f32 | 20 | myled = 1; // LED is ON |
selvakumararm | 0:bcf6fcde4f32 | 21 | wait(0.2); // 200 ms |
selvakumararm | 0:bcf6fcde4f32 | 22 | myled = 0; // LED is OFF |
selvakumararm | 0:bcf6fcde4f32 | 23 | wait(0.2); |
selvakumararm | 0:bcf6fcde4f32 | 24 | myled = 1; // LED is ON |
selvakumararm | 0:bcf6fcde4f32 | 25 | wait(0.2); // 200 ms |
selvakumararm | 0:bcf6fcde4f32 | 26 | myled = 0; // LED is OFF |
selvakumararm | 0:bcf6fcde4f32 | 27 | wait(1.0); // 1 sec |
selvakumararm | 0:bcf6fcde4f32 | 28 | } |
selvakumararm | 0:bcf6fcde4f32 | 29 | else{ |
selvakumararm | 0:bcf6fcde4f32 | 30 | myled = 0; |
selvakumararm | 0:bcf6fcde4f32 | 31 | } |
selvakumararm | 0:bcf6fcde4f32 | 32 | __wfi(); //Wait for interruptions |
selvakumararm | 0:bcf6fcde4f32 | 33 | } |
selvakumararm | 0:bcf6fcde4f32 | 34 | } |
selvakumararm | 0:bcf6fcde4f32 | 35 | |
selvakumararm | 0:bcf6fcde4f32 | 36 |