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: SharpDigiDist100/SharpDigiDist100.cpp
- Revision:
- 0:a29bcf098632
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/SharpDigiDist100/SharpDigiDist100.cpp Mon Jun 18 09:27:10 2012 +0000
@@ -0,0 +1,56 @@
+#include "SharpDigiDist100.h"
+
+SharpDigiDist100::SharpDigiDist100(PinName pin):intin(pin),pinin(pin)
+{
+timer1.reset();
+intin.rise(this,&SharpDigiDist100::onInt);
+intin.fall(this,&SharpDigiDist100::onInt);
+timer1.start();
+//onInt();
+current = Far;
+//last = NA;
+onChangeAttached = false;
+}
+
+void SharpDigiDist100::onInt()
+{
+ timer1.stop();
+ last = current;
+ int timeFromLast = timer1.read_ms();
+ if (timeFromLast < 100)
+ {
+ current = Far;
+ timeout.attach(this,&SharpDigiDist100::onInt, 0.3);
+ }
+ else
+ {
+ if(pinin)
+ {
+ current = Mid;
+ }
+ else
+ {
+ current = Near;
+ }
+ }
+ if(current != last)
+ {
+ if(onChangeAttached)
+ {
+ onChange();
+ }
+ }
+ timer1.reset();
+ timer1.start();
+}
+
+int SharpDigiDist100::getDistance()
+{
+ return current;
+}
+
+void SharpDigiDist100::attachOnChange(void (*ptr) (void))
+{
+ onChange = ptr;
+ onChangeAttached = true;
+}
\ No newline at end of file