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

Dependents:   CatPot_SensorRight_F CatPot_SensorRight_T

Committer:
ryuna
Date:
Thu Feb 26 05:30:39 2015 +0000
Revision:
0:bb38fe5771fb
this program is use meny loop .  ???????????

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ryuna 0:bb38fe5771fb 1 /* mbed Ping Library respected Library !!
ryuna 0:bb38fe5771fb 2 *
ryuna 0:bb38fe5771fb 3 * make interruptin_mod by bousiya03
ryuna 0:bb38fe5771fb 4 *
ryuna 0:bb38fe5771fb 5 */
ryuna 0:bb38fe5771fb 6
ryuna 0:bb38fe5771fb 7
ryuna 0:bb38fe5771fb 8 #include "IRM2121.h"
ryuna 0:bb38fe5771fb 9 #include "mbed.h"
ryuna 0:bb38fe5771fb 10
ryuna 0:bb38fe5771fb 11 IRM2121::IRM2121(PinName IRM_PIN)
ryuna 0:bb38fe5771fb 12 : _pin(IRM_PIN), _timer()
ryuna 0:bb38fe5771fb 13 {
ryuna 0:bb38fe5771fb 14
ryuna 0:bb38fe5771fb 15 }
ryuna 0:bb38fe5771fb 16
ryuna 0:bb38fe5771fb 17 unsigned int IRM2121::Read(void)
ryuna 0:bb38fe5771fb 18 // 0 means not valid.
ryuna 0:bb38fe5771fb 19 {
ryuna 0:bb38fe5771fb 20
ryuna 0:bb38fe5771fb 21
ryuna 0:bb38fe5771fb 22 _timer.reset();
ryuna 0:bb38fe5771fb 23 _timer.start();
ryuna 0:bb38fe5771fb 24
ryuna 0:bb38fe5771fb 25 while(_pin){
ryuna 0:bb38fe5771fb 26 if(_timer.read_us() > NAKATA){
ryuna 0:bb38fe5771fb 27 _timer.stop();
ryuna 0:bb38fe5771fb 28 return NOT_F;
ryuna 0:bb38fe5771fb 29 }
ryuna 0:bb38fe5771fb 30 }
ryuna 0:bb38fe5771fb 31
ryuna 0:bb38fe5771fb 32 _timer.reset();
ryuna 0:bb38fe5771fb 33
ryuna 0:bb38fe5771fb 34 while(!_pin){
ryuna 0:bb38fe5771fb 35 if(_timer.read_us() > NAKATA){
ryuna 0:bb38fe5771fb 36 _timer.stop();
ryuna 0:bb38fe5771fb 37 return NOT_F;
ryuna 0:bb38fe5771fb 38 }
ryuna 0:bb38fe5771fb 39 }
ryuna 0:bb38fe5771fb 40 _Time = _timer.read_us();
ryuna 0:bb38fe5771fb 41 while(_pin){
ryuna 0:bb38fe5771fb 42 if((_timer.read_us() -_Time) > NAKATA){
ryuna 0:bb38fe5771fb 43 _timer.stop();
ryuna 0:bb38fe5771fb 44 return NOT_F;
ryuna 0:bb38fe5771fb 45 }
ryuna 0:bb38fe5771fb 46 }
ryuna 0:bb38fe5771fb 47
ryuna 0:bb38fe5771fb 48 _Time = _timer.read_us() - _Time;
ryuna 0:bb38fe5771fb 49 _timer.stop();
ryuna 0:bb38fe5771fb 50 return _Time;
ryuna 0:bb38fe5771fb 51 }