avnish aggarwal
/
Bootcamp-InterruptCounter
ok - fix input pin
Diff: main.cpp
- Revision:
- 0:801eef032b63
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Wed Aug 07 19:44:57 2013 +0000 @@ -0,0 +1,30 @@ + +#include "mbed.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 + } + + void increment() { + _count++; + } + + int read() { + return _count; + } + +private: + InterruptIn _interrupt; + volatile int _count; +}; + +Counter counter(p5); + +int main() { + while(1) { + printf("Count so far: %d\n", counter.read()); + wait(2); + } +} \ No newline at end of file