DigitalIn,Timer を使用した ボール検知用ライブラリ

Dependents:   CatPot_SensorRight_F CatPot_SensorRight_T

Files at this revision

API Documentation at this revision

Comitter:
ryuna
Date:
Thu Feb 26 05:30:39 2015 +0000
Commit message:
this program is use meny loop . ???????????

Changed in this revision

IRM2121.cpp Show annotated file Show diff for this revision Revisions of this file
IRM2121.h Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/IRM2121.cpp	Thu Feb 26 05:30:39 2015 +0000
@@ -0,0 +1,51 @@
+/* mbed Ping Library respected Library !!
+ *
+ * make interruptin_mod by bousiya03
+ * 
+ */
+
+
+#include "IRM2121.h"
+#include "mbed.h"
+
+IRM2121::IRM2121(PinName IRM_PIN)
+        : _pin(IRM_PIN), _timer()
+{          
+
+} 
+        
+unsigned int IRM2121::Read(void)
+// 0 means not valid.
+{
+    
+     
+    _timer.reset();
+    _timer.start();
+    
+    while(_pin){
+     if(_timer.read_us() > NAKATA){
+        _timer.stop();
+        return NOT_F;
+     }  
+    }
+    
+    _timer.reset();
+    
+    while(!_pin){
+     if(_timer.read_us() > NAKATA){
+        _timer.stop();
+        return NOT_F;
+     }   
+    }
+    _Time = _timer.read_us();
+    while(_pin){
+      if((_timer.read_us() -_Time) > NAKATA){
+        _timer.stop();
+        return NOT_F;
+      }  
+    }
+    
+    _Time = _timer.read_us() - _Time;
+    _timer.stop();
+    return _Time;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/IRM2121.h	Thu Feb 26 05:30:39 2015 +0000
@@ -0,0 +1,62 @@
+
+    
+ #ifndef MBED_IRM_H
+ #define MBED_IRM_H
+
+#include "mbed.h"
+
+#define NAKATA 833 //周期833us
+#define NOT_F 0
+
+/** IRM2121  class, based on an DigitalIn pin, and a timer
+ *  use RoboCup Junior Soccer to find PULSE BALL.
+ 
+ 
+ * Example:
+ * @code
+ * // Set Digital and read sensor.
+ * #include "mbed.h"
+ * #include "IRM2121.h"
+ * IRM2121 IR(p21);
+ * 
+ * int main() {
+ *     int length;
+ 
+ *     while(1) {
+ *  
+ *        IR.Set();    
+ *        wait_ms(20); //check _Busy 1 &_Valid 0 ....config just wait time.
+ *        length = IR.Read();
+ *     }
+ * }
+ * @endcode
+ */
+class IRM2121 {
+  public:
+    /** Create a IRM2121 object connected to the specified InterruptIn pin
+    *
+    * @param IRM_PIN InterruptIn pin to connect to 
+    */
+    IRM2121(PinName IRM_PIN);
+    
+    unsigned int Read (void);    
+     /** Set a IRM2121 Interrupt Pin 
+      *
+      * @param none
+      */
+        
+    /** Read the result 
+      *
+      * @param none
+      */
+    
+  private:
+    
+    DigitalIn       _pin;
+    Timer           _timer;
+
+    unsigned int _Time;
+      
+  };
+  
+  #endif
\ No newline at end of file