
Counts Interrupts From Joystick
Fork of Bootcamp-InterruptCounter by
main.cpp@1:6d3ead04d296, 2013-12-11 (annotated)
- Committer:
- Cabal51
- Date:
- Wed Dec 11 20:10:01 2013 +0000
- Revision:
- 1:6d3ead04d296
- Parent:
- 0:801eef032b63
Lab3 Interrupt Counter
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
avnisha | 0:801eef032b63 | 1 | |
avnisha | 0:801eef032b63 | 2 | #include "mbed.h" |
Cabal51 | 1:6d3ead04d296 | 3 | #include "C12832_lcd.h" |
avnisha | 0:801eef032b63 | 4 | |
avnisha | 0:801eef032b63 | 5 | class Counter { |
avnisha | 0:801eef032b63 | 6 | public: |
avnisha | 0:801eef032b63 | 7 | Counter(PinName pin) : _interrupt(pin) { // create the InterruptIn on the pin specified to Counter |
avnisha | 0:801eef032b63 | 8 | _interrupt.rise(this, &Counter::increment); // attach increment function of this counter instance |
Cabal51 | 1:6d3ead04d296 | 9 | _interrupt.fall(this, &Counter::increment); |
avnisha | 0:801eef032b63 | 10 | } |
avnisha | 0:801eef032b63 | 11 | |
avnisha | 0:801eef032b63 | 12 | void increment() { |
avnisha | 0:801eef032b63 | 13 | _count++; |
avnisha | 0:801eef032b63 | 14 | } |
avnisha | 0:801eef032b63 | 15 | |
avnisha | 0:801eef032b63 | 16 | int read() { |
avnisha | 0:801eef032b63 | 17 | return _count; |
avnisha | 0:801eef032b63 | 18 | } |
avnisha | 0:801eef032b63 | 19 | |
avnisha | 0:801eef032b63 | 20 | private: |
avnisha | 0:801eef032b63 | 21 | InterruptIn _interrupt; |
avnisha | 0:801eef032b63 | 22 | volatile int _count; |
avnisha | 0:801eef032b63 | 23 | }; |
Cabal51 | 1:6d3ead04d296 | 24 | |
Cabal51 | 1:6d3ead04d296 | 25 | |
Cabal51 | 1:6d3ead04d296 | 26 | C12832_LCD lcd; |
Cabal51 | 1:6d3ead04d296 | 27 | Counter counter(p14); |
Cabal51 | 1:6d3ead04d296 | 28 | |
avnisha | 0:801eef032b63 | 29 | int main() { |
avnisha | 0:801eef032b63 | 30 | while(1) { |
Cabal51 | 1:6d3ead04d296 | 31 | |
Cabal51 | 1:6d3ead04d296 | 32 | lcd.locate(0,0); |
Cabal51 | 1:6d3ead04d296 | 33 | lcd.printf("Count so far: %d\n", counter.read()); |
Cabal51 | 1:6d3ead04d296 | 34 | wait(0.5); |
avnisha | 0:801eef032b63 | 35 | } |
avnisha | 0:801eef032b63 | 36 | } |