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: mbed
main.cpp@1:d174c4427e69, 2019-11-15 (annotated)
- Committer:
- YUPPY
- Date:
- Fri Nov 15 12:42:26 2019 +0000
- Revision:
- 1:d174c4427e69
- Parent:
- 0:2acb3f965991
- Child:
- 2:d3675b786834
US015sb612 Completed
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
KINU | 0:2acb3f965991 | 1 | #include "mbed.h" |
KINU | 0:2acb3f965991 | 2 | #include "us015.h" |
KINU | 0:2acb3f965991 | 3 | DigitalOut myled(LED1); |
KINU | 0:2acb3f965991 | 4 | US015 hs(p12,p11); |
KINU | 0:2acb3f965991 | 5 | DigitalOut thermo(p20); |
KINU | 0:2acb3f965991 | 6 | DigitalOut Ultra(p12); |
YUPPY | 1:d174c4427e69 | 7 | Serial pc(USBTX,USBRX); // tx, rx |
KINU | 0:2acb3f965991 | 8 | |
KINU | 0:2acb3f965991 | 9 | int main(){ |
KINU | 0:2acb3f965991 | 10 | float th; |
KINU | 0:2acb3f965991 | 11 | Timer tm; |
KINU | 0:2acb3f965991 | 12 | pc.printf("start\r\n"); |
KINU | 0:2acb3f965991 | 13 | |
KINU | 0:2acb3f965991 | 14 | bool detected=false; |
KINU | 0:2acb3f965991 | 15 | thermo=0; //焦電off |
KINU | 0:2acb3f965991 | 16 | Ultra=1;//超音波on |
KINU | 0:2acb3f965991 | 17 | |
KINU | 0:2acb3f965991 | 18 | while(1) { |
KINU | 0:2acb3f965991 | 19 | hs.TrigerOut(); |
KINU | 0:2acb3f965991 | 20 | wait(1); |
KINU | 0:2acb3f965991 | 21 | int distance; |
KINU | 0:2acb3f965991 | 22 | distance = hs.GetDistance(); |
KINU | 0:2acb3f965991 | 23 | printf("%d\r\n",distance);//距離出力 |
KINU | 0:2acb3f965991 | 24 | |
YUPPY | 1:d174c4427e69 | 25 | if(distance<2000){//超音波反応 |
KINU | 0:2acb3f965991 | 26 | Ultra=0;//超音波off |
KINU | 0:2acb3f965991 | 27 | thermo=1;//焦電on |
KINU | 0:2acb3f965991 | 28 | if(true) |
KINU | 0:2acb3f965991 | 29 | th = thermo; |
KINU | 0:2acb3f965991 | 30 | if(th=1 && !detected) {//焦電反応ありの場合 |
KINU | 0:2acb3f965991 | 31 | detected=true; |
KINU | 0:2acb3f965991 | 32 | pc.printf("human\r\n"); |
KINU | 0:2acb3f965991 | 33 | tm.reset(); |
KINU | 0:2acb3f965991 | 34 | tm.start(); |
KINU | 0:2acb3f965991 | 35 | }else{//焦電反応なしの場合 |
KINU | 0:2acb3f965991 | 36 | detected=false; |
KINU | 0:2acb3f965991 | 37 | } |
KINU | 0:2acb3f965991 | 38 | |
KINU | 0:2acb3f965991 | 39 | } |
KINU | 0:2acb3f965991 | 40 | //while(true) |
KINU | 0:2acb3f965991 | 41 | } |
YUPPY | 1:d174c4427e69 | 42 | return 0; |
KINU | 0:2acb3f965991 | 43 | } |
KINU | 0:2acb3f965991 | 44 |