Dependencies:   mbed

Committer:
joe
Date:
Fri Aug 20 15:38:52 2010 +0000
Revision:
2:a079de4fd5b9
Parent:
0:960b355eaa84

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
joe 0:960b355eaa84 1 #include "mbed.h"
joe 0:960b355eaa84 2 #include "Counter.h"
joe 0:960b355eaa84 3
joe 0:960b355eaa84 4 Counter::Counter(PinName pin)
joe 0:960b355eaa84 5 : _interrupt (pin) {
joe 0:960b355eaa84 6
joe 0:960b355eaa84 7 // attach rising edge to rising function
joe 0:960b355eaa84 8 _interrupt.rise(this, &Counter::rising);
joe 0:960b355eaa84 9
joe 0:960b355eaa84 10 // Initialise the counter to 0
joe 0:960b355eaa84 11 _count = 0;
joe 0:960b355eaa84 12 }
joe 0:960b355eaa84 13
joe 0:960b355eaa84 14 // On a rising edge, increment the counter
joe 0:960b355eaa84 15 void Counter::rising() {
joe 0:960b355eaa84 16 _count++;
joe 0:960b355eaa84 17 }
joe 0:960b355eaa84 18
joe 0:960b355eaa84 19 // return the current count
joe 0:960b355eaa84 20 int Counter::read() {
joe 0:960b355eaa84 21 return _count;
joe 0:960b355eaa84 22 }
joe 0:960b355eaa84 23
joe 0:960b355eaa84 24 // Reset the counter
joe 0:960b355eaa84 25 void Counter::reset() {
joe 0:960b355eaa84 26 _count = 0;
joe 0:960b355eaa84 27 }
joe 0:960b355eaa84 28