An interrupt option to using the Magnetic Reed Switch Sensor

Dependencies:   mbed

Committer:
Alexw2011
Date:
Mon Mar 14 14:33:36 2016 +0000
Revision:
0:4c661890a5cd
Interrupt

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Alexw2011 0:4c661890a5cd 1 #include "mbed.h"
Alexw2011 0:4c661890a5cd 2 #include "Speaker.h"
Alexw2011 0:4c661890a5cd 3
Alexw2011 0:4c661890a5cd 4 InterruptIn MagSense(p16);
Alexw2011 0:4c661890a5cd 5 DigitalOut Blink(LED4);
Alexw2011 0:4c661890a5cd 6 Speaker Interrupt(p21);
Alexw2011 0:4c661890a5cd 7
Alexw2011 0:4c661890a5cd 8 void flip() {
Alexw2011 0:4c661890a5cd 9
Alexw2011 0:4c661890a5cd 10 while(1){
Alexw2011 0:4c661890a5cd 11
Alexw2011 0:4c661890a5cd 12 Interrupt.PlayNote(969, 0.1, 1.0); // When contact is broken, interrupt the main program and sound the alarm
Alexw2011 0:4c661890a5cd 13 Interrupt.PlayNote(800, 0.1, 1.0);
Alexw2011 0:4c661890a5cd 14 }
Alexw2011 0:4c661890a5cd 15
Alexw2011 0:4c661890a5cd 16 }
Alexw2011 0:4c661890a5cd 17
Alexw2011 0:4c661890a5cd 18 int main() {
Alexw2011 0:4c661890a5cd 19 MagSense.rise(&flip); // attach the address of the flip function to the rising edge
Alexw2011 0:4c661890a5cd 20 while(1) { // Do this until contact is broken
Alexw2011 0:4c661890a5cd 21 Blink = !Blink;
Alexw2011 0:4c661890a5cd 22 wait(0.25);
Alexw2011 0:4c661890a5cd 23 }
Alexw2011 0:4c661890a5cd 24 }