Solution
Dependencies: ELEC350-Practicals-FZ429
Fork of Task650-mbedos-FZ429ZI-eventloop by
Diff: main.cpp
- Revision:
- 12:01c7edd1dd19
- Parent:
- 11:67cb33bc247e
--- 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