Example program using interrupts with PIR motion sensor.

Dependencies:   mbed

Committer:
awood37
Date:
Fri Mar 06 22:02:17 2015 +0000
Revision:
0:8aaf23a881c1

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
awood37 0:8aaf23a881c1 1 #include "mbed.h"
awood37 0:8aaf23a881c1 2 //example using InterruptIn with the input from the PIR motion sensors
awood37 0:8aaf23a881c1 3 InterruptIn alarm(p11);
awood37 0:8aaf23a881c1 4 DigitalOut led(LED1);
awood37 0:8aaf23a881c1 5 DigitalOut flash(LED4);
awood37 0:8aaf23a881c1 6
awood37 0:8aaf23a881c1 7 void flip() {
awood37 0:8aaf23a881c1 8 led = !led;
awood37 0:8aaf23a881c1 9 }
awood37 0:8aaf23a881c1 10
awood37 0:8aaf23a881c1 11 int main() {
awood37 0:8aaf23a881c1 12 alarm.mode(PullUp);
awood37 0:8aaf23a881c1 13 wait(2);
awood37 0:8aaf23a881c1 14 alarm.fall(&flip); // attach the address of the flip function to the falling edge
awood37 0:8aaf23a881c1 15 while(1) { // wait around, interrupts will interrupt
awood37 0:8aaf23a881c1 16 flash = !flash;
awood37 0:8aaf23a881c1 17 wait(0.25);
awood37 0:8aaf23a881c1 18 }
awood37 0:8aaf23a881c1 19 }