![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Test code for interfacing to megasquirt ECU.
Diff: Counter/Counter.cpp
- Revision:
- 0:cf99a7b873b3
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Counter/Counter.cpp Sat Feb 14 08:50:32 2015 +0000 @@ -0,0 +1,40 @@ +#include "mbed.h" +#include "Counter.h" + +/*=====================================================================================*/ +// Counter object, which also setups up irq +/*=====================================================================================*/ + +//from http://mbed.org/handbook/InterruptIn, modified to add debouncing + +Counter::Counter(PinName pin, void (*function)(void)) : _interrupt(pin) { // create the InterruptIn on the pin specified to Counter + _interrupt.fall(this, &Counter::increment); // attach increment function of this counter instance + jim.attach(function); + t.start(); // timer start + } + +void Counter::increment() { + if ( t.read_ms() > DEBOUNCING_INTERVAL ) { + _count++; + time_t seconds = time(NULL); + // RingWriteToBuffer(seconds); + + jim.call(); + + } + t.reset(); // timer reset +} + +int Counter::read() { + return _count; +} + +int Counter::set(int val) { + int was = _count; + _count = val; + return was; +} + +void Counter::reset() { + _count = 0; + }