Gabriel Smakaj
/
Test
Smakaj
Diff: main.cpp
- Revision:
- 0:cc2bde387551
- Child:
- 1:3edc991805bd
diff -r 000000000000 -r cc2bde387551 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Thu Nov 29 17:19:32 2018 +0000 @@ -0,0 +1,30 @@ +#include "mbed.h" +class IsAnEvent : public InterruptIn { + volatile int16_t _pressed; + void _RisingISR(); + public: + IsAnEvent() : InterruptIn(p15) {}; + IsAnEvent(PinName pin) : InterruptIn(pin) { + rise(callback(this, &IsAnEvent::_RisingISR)); + _pressed=0; + }; + int CheckFlag(); + void InitIsr(); +}; + +void IsAnEvent::InitIsr() { + rise(callback(this, &IsAnEvent::_RisingISR)); +} + +void IsAnEvent::_RisingISR() { + wait_ms(50); + if( read() ) + _pressed = true; +} +int IsAnEvent::CheckFlag() { + if( _pressed ) { + _pressed = false; + return 1; + } + return 0; +} \ No newline at end of file