DigitalIn,Timer を使用した ボール検知用ライブラリ
Dependents: CatPot_SensorRight_F CatPot_SensorRight_T
Diff: IRM2121.cpp
- Revision:
- 0:bb38fe5771fb
--- /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; +}