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@3:f7f92004d3ac, 2019-11-28 (annotated)
- Committer:
- YUPPY
- Date:
- Thu Nov 28 06:53:24 2019 +0000
- Revision:
- 3:f7f92004d3ac
- Parent:
- 2:d3675b786834
- Child:
- 4:7cffa8775a27
s;
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"); |
YUPPY | 2:d3675b786834 | 13 | thermo=0; //焦電off |
YUPPY | 2:d3675b786834 | 14 | printf("焦電Off\r\n"); |
YUPPY | 2:d3675b786834 | 15 | Ultra=1;//超音波on |
YUPPY | 2:d3675b786834 | 16 | printf("超音波On\r\n"); |
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(); |
YUPPY | 2:d3675b786834 | 23 | printf("distance=%d\r\n",distance);//距離出力 |
KINU | 0:2acb3f965991 | 24 | |
YUPPY | 2:d3675b786834 | 25 | if(distance<=2000){//超音波反応 |
KINU | 0:2acb3f965991 | 26 | Ultra=0;//超音波off |
YUPPY | 2:d3675b786834 | 27 | |
KINU | 0:2acb3f965991 | 28 | thermo=1;//焦電on |
YUPPY | 2:d3675b786834 | 29 | bool detected=false; |
YUPPY | 2:d3675b786834 | 30 | if(true){ |
KINU | 0:2acb3f965991 | 31 | th = thermo; |
YUPPY | 3:f7f92004d3ac | 32 | if(th==1 && !detected) {//焦電反応ありの場合 |
KINU | 0:2acb3f965991 | 33 | detected=true; |
KINU | 0:2acb3f965991 | 34 | pc.printf("human\r\n"); |
KINU | 0:2acb3f965991 | 35 | tm.reset(); |
KINU | 0:2acb3f965991 | 36 | tm.start(); |
YUPPY | 2:d3675b786834 | 37 | } |
YUPPY | 2:d3675b786834 | 38 | else if(tm.read_ms()>5000){//焦電反応なしの場合 |
YUPPY | 2:d3675b786834 | 39 | printf("not found\r\n"); |
YUPPY | 3:f7f92004d3ac | 40 | thermo=0; |
YUPPY | 3:f7f92004d3ac | 41 | printf("焦電OFF\r\n"); |
YUPPY | 3:f7f92004d3ac | 42 | Ultra=1; |
YUPPY | 3:f7f92004d3ac | 43 | printf("超音波ONっすよ!\r\n"); |
KINU | 0:2acb3f965991 | 44 | detected=false; |
KINU | 0:2acb3f965991 | 45 | } |
KINU | 0:2acb3f965991 | 46 | |
YUPPY | 3:f7f92004d3ac | 47 | }//if(true) |
YUPPY | 2:d3675b786834 | 48 | }if(distance>2000){//超音波反応遠い |
YUPPY | 2:d3675b786834 | 49 | printf("distance>2000だぞ\r\n"); |
YUPPY | 2:d3675b786834 | 50 | } |
YUPPY | 3:f7f92004d3ac | 51 | //while(1) |
KINU | 0:2acb3f965991 | 52 | } |
YUPPY | 2:d3675b786834 | 53 | |
YUPPY | 2:d3675b786834 | 54 | |
YUPPY | 2:d3675b786834 | 55 | return 0; |
YUPPY | 3:f7f92004d3ac | 56 | } |