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@4:7cffa8775a27, 2019-11-28 (annotated)
- Committer:
- YUPPY
- Date:
- Thu Nov 28 08:05:11 2019 +0000
- Revision:
- 4:7cffa8775a27
- Parent:
- 3:f7f92004d3ac
yeah
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); |
YUPPY | 4:7cffa8775a27 | 5 | DigitalIn thermo(p20); |
YUPPY | 4:7cffa8775a27 | 6 | DigitalOut Sb612switch(p15); |
KINU | 0:2acb3f965991 | 7 | DigitalOut Ultra(p12); |
YUPPY | 1:d174c4427e69 | 8 | Serial pc(USBTX,USBRX); // tx, rx |
KINU | 0:2acb3f965991 | 9 | |
KINU | 0:2acb3f965991 | 10 | int main(){ |
KINU | 0:2acb3f965991 | 11 | float th; |
KINU | 0:2acb3f965991 | 12 | Timer tm; |
KINU | 0:2acb3f965991 | 13 | pc.printf("start\r\n"); |
YUPPY | 4:7cffa8775a27 | 14 | Sb612switch=0; //焦電off |
YUPPY | 2:d3675b786834 | 15 | printf("焦電Off\r\n"); |
YUPPY | 2:d3675b786834 | 16 | Ultra=1;//超音波on |
YUPPY | 2:d3675b786834 | 17 | printf("超音波On\r\n"); |
KINU | 0:2acb3f965991 | 18 | |
KINU | 0:2acb3f965991 | 19 | while(1) { |
KINU | 0:2acb3f965991 | 20 | hs.TrigerOut(); |
KINU | 0:2acb3f965991 | 21 | wait(1); |
KINU | 0:2acb3f965991 | 22 | int distance; |
KINU | 0:2acb3f965991 | 23 | distance = hs.GetDistance(); |
YUPPY | 2:d3675b786834 | 24 | printf("distance=%d\r\n",distance);//距離出力 |
KINU | 0:2acb3f965991 | 25 | |
YUPPY | 2:d3675b786834 | 26 | if(distance<=2000){//超音波反応 |
KINU | 0:2acb3f965991 | 27 | Ultra=0;//超音波off |
YUPPY | 2:d3675b786834 | 28 | |
YUPPY | 4:7cffa8775a27 | 29 | Sb612switch=1;//焦電on |
YUPPY | 2:d3675b786834 | 30 | bool detected=false; |
YUPPY | 4:7cffa8775a27 | 31 | |
KINU | 0:2acb3f965991 | 32 | th = thermo; |
YUPPY | 3:f7f92004d3ac | 33 | if(th==1 && !detected) {//焦電反応ありの場合 |
KINU | 0:2acb3f965991 | 34 | detected=true; |
KINU | 0:2acb3f965991 | 35 | pc.printf("human\r\n"); |
KINU | 0:2acb3f965991 | 36 | tm.reset(); |
KINU | 0:2acb3f965991 | 37 | tm.start(); |
YUPPY | 2:d3675b786834 | 38 | } |
YUPPY | 4:7cffa8775a27 | 39 | else{//焦電反応なしの場合 |
YUPPY | 2:d3675b786834 | 40 | printf("not found\r\n"); |
YUPPY | 4:7cffa8775a27 | 41 | Sb612switch=0; |
YUPPY | 3:f7f92004d3ac | 42 | Ultra=1; |
KINU | 0:2acb3f965991 | 43 | detected=false; |
KINU | 0:2acb3f965991 | 44 | } |
KINU | 0:2acb3f965991 | 45 | |
YUPPY | 4:7cffa8775a27 | 46 | |
YUPPY | 2:d3675b786834 | 47 | }if(distance>2000){//超音波反応遠い |
YUPPY | 2:d3675b786834 | 48 | printf("distance>2000だぞ\r\n"); |
YUPPY | 2:d3675b786834 | 49 | } |
YUPPY | 3:f7f92004d3ac | 50 | //while(1) |
KINU | 0:2acb3f965991 | 51 | } |
YUPPY | 2:d3675b786834 | 52 | |
YUPPY | 2:d3675b786834 | 53 | |
YUPPY | 2:d3675b786834 | 54 | return 0; |
YUPPY | 3:f7f92004d3ac | 55 | } |