Allows the M3Pi to be used as a Sumo robot, using the sharp 100 distance sensors on the front. Hunter strategy

Dependencies:   mbed

Revision:
0:a29bcf098632
diff -r 000000000000 -r a29bcf098632 SharpDigiDist100/SharpDigiDist100.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SharpDigiDist100/SharpDigiDist100.h	Mon Jun 18 09:27:10 2012 +0000
@@ -0,0 +1,75 @@
+#ifndef SHARPDIGIDIST100_H
+#define SHARPDIGIDIST100_H
+
+#include "mbed.h"
+
+/** A class which interfaces with  a Sharp Digital Distance sensor (GP2Y0D810)
+ *
+ *  Example:
+ * @code
+ * 
+ * @endcode
+ *
+ */
+
+class SharpDigiDist100
+{
+public:
+
+/** Create a sensor input
+ *
+ * @param pin The pin the output of the sensor is connected to
+ */
+ 
+SharpDigiDist100(PinName pin);
+
+/** The enum which makes up the output
+ * 
+ */
+
+enum Distance
+{
+    Near = 1,
+    Mid,
+    Far
+};
+
+/** Returns the distace as an enum
+ *
+ * @return The distance code: 1 is near, 2 is middle distance and 3 is far
+ */
+ 
+int getDistance();
+
+/** Attaches a function which is called on distance change
+ *
+ * @param A pointer to a function with params/returns: void func(void)
+ */
+
+void attachOnChange(void (*ptr) (void));
+
+
+protected:
+
+InterruptIn intin;
+
+DigitalIn pinin;
+
+Timer timer1;
+
+enum Distance current;
+
+enum Distance last;
+
+void onInt();
+
+Timeout timeout;
+
+void (*onChange) (void);
+
+bool onChangeAttached;
+
+//DigitalOut Debug;
+};
+
+#endif
\ No newline at end of file