Counts Interrupts From Joystick

Dependencies:   C12832_lcd mbed

Fork of Bootcamp-InterruptCounter by avnish aggarwal

Committer:
avnisha
Date:
Wed Aug 07 19:44:57 2013 +0000
Revision:
0:801eef032b63
Child:
1:6d3ead04d296
ok

Who changed what in which revision?

UserRevisionLine numberNew contents of line
avnisha 0:801eef032b63 1
avnisha 0:801eef032b63 2 #include "mbed.h"
avnisha 0:801eef032b63 3
avnisha 0:801eef032b63 4 class Counter {
avnisha 0:801eef032b63 5 public:
avnisha 0:801eef032b63 6 Counter(PinName pin) : _interrupt(pin) { // create the InterruptIn on the pin specified to Counter
avnisha 0:801eef032b63 7 _interrupt.rise(this, &Counter::increment); // attach increment function of this counter instance
avnisha 0:801eef032b63 8 }
avnisha 0:801eef032b63 9
avnisha 0:801eef032b63 10 void increment() {
avnisha 0:801eef032b63 11 _count++;
avnisha 0:801eef032b63 12 }
avnisha 0:801eef032b63 13
avnisha 0:801eef032b63 14 int read() {
avnisha 0:801eef032b63 15 return _count;
avnisha 0:801eef032b63 16 }
avnisha 0:801eef032b63 17
avnisha 0:801eef032b63 18 private:
avnisha 0:801eef032b63 19 InterruptIn _interrupt;
avnisha 0:801eef032b63 20 volatile int _count;
avnisha 0:801eef032b63 21 };
avnisha 0:801eef032b63 22
avnisha 0:801eef032b63 23 Counter counter(p5);
avnisha 0:801eef032b63 24
avnisha 0:801eef032b63 25 int main() {
avnisha 0:801eef032b63 26 while(1) {
avnisha 0:801eef032b63 27 printf("Count so far: %d\n", counter.read());
avnisha 0:801eef032b63 28 wait(2);
avnisha 0:801eef032b63 29 }
avnisha 0:801eef032b63 30 }