Interrupt

Dependencies:   mbed

main.cpp

Committer:
corsa1600
Date:
2019-02-04
Revision:
0:1992191bb2b6

File content as of revision 0:1992191bb2b6:

#include "mbed.h"
 
DigitalOut led (LED1);
 
 
class SwEvent
{
    private:
        InterruptIn  _isr;
        bool _check;
    public:    
        SwEvent(PinName isr):_isr(isr) 
        {
            _isr.rise(callback(this, &SwEvent::setFlag));    
        }
        
        bool checkFlag(void);
        void setFlag(void);
};
 
 
 
void SwEvent::setFlag(void)
{
    _check = !_check;
}
 
bool SwEvent::checkFlag(void)
{
    
        if (_check == 0) led = 1;
        else if (_check == 1) led = 0;  
        
        return _check;
}
 
SwEvent checker(p15);
 
int main() {
    while(1) {
        checker.checkFlag();
        printf("Aktueller Status: %d \n", checker.checkFlag());
        wait_ms(10);
    }
}