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.
Dependencies: RemoteIR TextLCD
Diff: main.cpp
- Revision:
- 21:68d38e8f64b5
- Parent:
- 20:02bb875a9b13
- Child:
- 22:c6e2a3b9aa14
--- a/main.cpp Wed Aug 05 02:31:16 2020 +0000
+++ b/main.cpp Wed Aug 05 02:39:37 2020 +0000
@@ -412,35 +412,34 @@
/* 距離計測関数 */
int watch(){
- trig = 0;
- ThisThread::sleep_for(5); // 5ms待つ
- trig = 1;
- ThisThread::sleep_for(15); // 15ms待つ
- trig = 0;
- timer.start();
- t1=timer.read_ms();
- t2=timer.read_ms();
- while(echo.read() == 0&&(t1-t2)<10){
+ do{
+ trig = 0;
+ ThisThread::sleep_for(5); // 5ms待つ
+ trig = 1;
+ ThisThread::sleep_for(15); // 15ms待つ
+ trig = 0;
+ timer.start();
t1=timer.read_ms();
- led1 = 1;
+ t2=timer.read_ms();
+ while(echo.read() == 0&&(t1-t2)<10){
+ t1=timer.read_ms();
+ led1 = 1;
+ }
+ timer.stop();
+ timer.reset();
+ if((t1-t2) >= 10){
+ run = STOP;
+ }
+ }while((t1-t2) >= 10);
+ timer.start(); // 距離計測タイマースタート
+ while(echo.read() == 1){
}
- timer.stop();
- timer.reset();
- if((t1-t2)<10){
- timer.start(); // 距離計測タイマースタート
- while(echo.read() == 1){
- }
- timer.stop(); // 距離計測タイマーストップ
- DT = (int)(timer.read_us()*0.01657); // 距離計算
- if(DT > 100){ // 検知範囲外なら100cmに設定
- DT = 100;
- }
- timer.reset(); // 距離計測タイマーリセット
+ timer.stop(); // 距離計測タイマーストップ
+ DT = (int)(timer.read_us()*0.01657); // 距離計算
+ if(DT > 100){ // 検知範囲外なら100cmに設定
+ DT = 100;
}
-
- if((t1-t2)>=10){
- run = STOP;
- }
+ timer.reset(); // 距離計測タイマーリセット
led1 = 0;
return DT;
}