Counts Interrupts From Joystick

Dependencies:   C12832_lcd mbed

Fork of Bootcamp-InterruptCounter by avnish aggarwal

main.cpp

Committer:
Cabal51
Date:
2013-12-11
Revision:
1:6d3ead04d296
Parent:
0:801eef032b63

File content as of revision 1:6d3ead04d296:


#include "mbed.h"
#include "C12832_lcd.h"
 
class Counter {
public:
    Counter(PinName pin) : _interrupt(pin) {        // create the InterruptIn on the pin specified to Counter
        _interrupt.rise(this, &Counter::increment); // attach increment function of this counter instance
        _interrupt.fall(this, &Counter::increment);
    }
 
    void increment() {
        _count++;
    }
 
    int read() {
        return _count;
    }
 
private:
    InterruptIn _interrupt;
    volatile int _count;
};


C12832_LCD lcd;
Counter counter(p14);

int main() {
    while(1) {
        
        lcd.locate(0,0);
        lcd.printf("Count so far: %d\n", counter.read());
        wait(0.5);
    }
}