cansat_B 2019 / Mbed 2 deprecated US015sb612Completed_Real

Dependencies:   mbed

main.cpp

Committer:
YUPPY
Date:
2019-11-22
Revision:
2:95a9db056db1
Parent:
1:d174c4427e69

File content as of revision 2:95a9db056db1:

#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
void us015(void);

int main(){
  float th;
  Timer tm;
  pc.printf("start\r\n");

  bool detected=false;
    thermo=0; //焦電off
    Ultra=1;//超音波on
   
    while(1) {
          int distance;
          us015();
        if(distance<2000){//超音波反応
         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)
  }
  
  }
   void us015(){
    hs.TrigerOut();
         wait(1);
         int distance;
         distance = hs.GetDistance();
         printf("%d\r\n",distance);//距離出力
         }