cansat_B 2019 / Mbed 2 deprecated US015sb612

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
KINU
Date:
Wed Nov 13 05:12:54 2019 +0000
Commit message:
US015sb612 1

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
us015.h Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r 2acb3f965991 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Wed Nov 13 05:12:54 2019 +0000
@@ -0,0 +1,44 @@
+#include "mbed.h"
+#include "us015.h"
+DigitalOut myled(LED1);
+US015 hs(p12,p11);
+DigitalOut thermo(p20);
+DigitalOut Ultra(p12);
+Serial pc(USBTX, USBRX); // tx, rx
+
+int main(){
+  float th;
+  Timer tm;
+  pc.baud(115200);
+  pc.printf("start\r\n");
+
+  bool detected=false;
+    thermo=0; //焦電off
+    Ultra=1;//超音波on
+   
+    while(1) {
+         hs.TrigerOut();
+         wait(1);
+         int distance;
+         distance = hs.GetDistance();
+         printf("%d\r\n",distance);//距離出力
+        
+        if(distance<200){//超音波反応
+         Ultra=0;//超音波off
+         thermo=1;//焦電on
+          if(true)
+             th = thermo;
+             if(th=1 && !detected) {//焦電反応ありの場合
+               detected=true;
+             pc.printf("human\r\n");
+             tm.reset();
+             tm.start();
+            }else{//焦電反応なしの場合
+             detected=false;
+             }
+           
+}
+  //while(true)
+  }
+  }
+  
\ No newline at end of file
diff -r 000000000000 -r 2acb3f965991 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Wed Nov 13 05:12:54 2019 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/mbed_official/code/mbed/builds/65be27845400
\ No newline at end of file
diff -r 000000000000 -r 2acb3f965991 us015.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/us015.h	Wed Nov 13 05:12:54 2019 +0000
@@ -0,0 +1,40 @@
+#ifndef __US015_H
+#define __US015_H
+
+#include "mbed.h"
+
+
+//====================================
+// define定義
+//====================================
+#define US015_TRIGER_ON             1    // トリガーON
+#define US015_TRIGER_OFF            0    // トリガーOFF
+#define US015_TRIGER_PALUSE_WIDTH   10   // トリガーの幅
+#define US015_PERIODIC_TRIGER 100000    // 音響測距トリガー
+#define US015_SOUND_OF_SPEED  0.340           // 音速[mm/us]
+
+
+//====================================
+// 音響測距センサ(US015)の制御クラス
+//====================================
+class US015
+{
+    public:
+        US015(PinName trg, PinName ech);
+        US015(PinName trg, PinName ech, float tkTime);
+        float GetDistance();
+        void TrigerOut();                       // トリガー出力
+        
+    private:
+        DigitalOut _trigerOut;                  // U015トリガー出力
+        InterruptIn _interruptEcho;             // U015エコー入力
+        Timer timer;                            // 時間計測用のタイマ
+        Ticker tk;                              // 周期処理用のチッカー
+        float tmBegin;                          // エコーの立ち上がり時間
+        float tmEnd;                            // エコーの立ち下がり時間
+        float distance;                         // 距離測定
+        void EchoFall();                        // エコーの立ち下がり処理
+        void EchoRise();                        // エコーの立ち上がり処理
+};
+
+#endif
\ No newline at end of file