Demonstration of EventQueues
Dependencies: ELEC350-Practicals-FZ429
Fork of Task622Solution-mbedos54 by
Revision 12:01c7edd1dd19, committed 2017-11-21
- Comitter:
- noutram
- Date:
- Tue Nov 21 13:50:04 2017 +0000
- Parent:
- 11:67cb33bc247e
- Commit message:
- Now addressed the issue of switch bounce
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 67cb33bc247e -r 01c7edd1dd19 main.cpp --- a/main.cpp Tue Nov 21 13:23:58 2017 +0000 +++ b/main.cpp Tue Nov 21 13:50:04 2017 +0000 @@ -3,6 +3,7 @@ #include "sample_hardware.hpp" #include "mbed_events.h" void buttonPressedISR(); +void buttonReleasedISR(); void addSample(float t); void heartBeat(); @@ -17,6 +18,15 @@ //Buffer float arrayOfTimes[10]; +//Set up rising edge detection +void rising() { + btn.rise(buttonPressedISR); +} +//Set up falling edge detection +void falling() { + btn.fall(buttonReleasedISR); +} + int main() { //Power on self test post(); @@ -41,7 +51,14 @@ void buttonPressedISR() { float t = tmr1.read(); //Immediately read time in seconds - mainQueue.call(addSample, t); + btn.rise(NULL); //Turn off interrupt + mainQueue.call(addSample, t); //Add sample to buffer and print + mainQueue.call_in(200, falling); //After 200ms, look for falling edge +} + +void buttonReleasedISR() { + btn.fall(NULL); //Turn off interrupt + mainQueue.call_in(200, rising); //After 200ms, look for rising edge again } // Add sample to buffer @@ -62,6 +79,7 @@ printf("%5.1f ", delta); } printf("\n"); + } //Flashing LED