![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Test code for interfacing to megasquirt ECU.
Counter/Counter.cpp
- Committer:
- jont
- Date:
- 2015-02-14
- Revision:
- 0:cf99a7b873b3
File content as of revision 0:cf99a7b873b3:
#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; }