Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: PulseWidthCounter/PulseWidthCounter.cpp
- Revision:
- 2:59ac9df97701
- Child:
- 8:1db19b529b22
diff -r caafe8935da6 -r 59ac9df97701 PulseWidthCounter/PulseWidthCounter.cpp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/PulseWidthCounter/PulseWidthCounter.cpp Fri Nov 15 20:53:36 2013 +0000
@@ -0,0 +1,28 @@
+#include "mbed.h"
+#include "InterruptIn.h"
+#include "PulseWidthCounter.h"
+
+PulseWidthCounter::PulseWidthCounter(PinName _interrupt,bool positive) : interrupt(_interrupt) //constructa
+{
+ if ( positive )
+ { interrupt.rise(this,&PulseWidthCounter::start);
+ interrupt.fall(this,&PulseWidthCounter::stop);
+ }
+ else
+ { interrupt.fall(this,&PulseWidthCounter::start);
+ interrupt.rise(this,&PulseWidthCounter::stop);
+ }
+}
+
+void PulseWidthCounter::start()
+{
+ _time.reset();
+ _time.start();
+}
+
+void PulseWidthCounter::stop()
+{
+ _time.stop();
+ count = _time.read_us();
+}
+