button trigger interrupt

Dependencies:   mbed

Committer:
bcostm
Date:
Fri Feb 21 12:53:03 2014 +0000
Revision:
0:912303e63cbd
Child:
1:19e910fda737
Initial version.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bcostm 0:912303e63cbd 1 #include "mbed.h"
bcostm 0:912303e63cbd 2
bcostm 0:912303e63cbd 3 InterruptIn mybutton(USER_BUTTON);
bcostm 0:912303e63cbd 4 DigitalOut myled(LED1);
bcostm 0:912303e63cbd 5
bcostm 0:912303e63cbd 6 float delay = 1.0; // 1 sec
bcostm 0:912303e63cbd 7
bcostm 0:912303e63cbd 8 void pressed()
bcostm 0:912303e63cbd 9 {
bcostm 0:912303e63cbd 10 if (delay == 1.0)
bcostm 0:912303e63cbd 11 delay = 0.2; // 200 ms
bcostm 0:912303e63cbd 12 else
bcostm 0:912303e63cbd 13 delay = 1.0; // 1 sec
bcostm 0:912303e63cbd 14 }
bcostm 0:912303e63cbd 15
bcostm 0:912303e63cbd 16 int main()
bcostm 0:912303e63cbd 17 {
bcostm 0:912303e63cbd 18 mybutton.fall(&pressed);
bcostm 0:912303e63cbd 19 while (1) {
bcostm 0:912303e63cbd 20 myled = !myled;
bcostm 0:912303e63cbd 21 wait(delay);
bcostm 0:912303e63cbd 22 }
bcostm 0:912303e63cbd 23 }