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.
main.cpp@9:e703afddc87e, 2019-12-06 (annotated)
- Committer:
- VPKD1669
- Date:
- Fri Dec 06 21:52:13 2019 +0000
- Revision:
- 9:e703afddc87e
- Parent:
- 8:25138f7b9309
IT WORKS EFFECTIVELY WITH ULTRASONIC SENSOR
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| andcor02 | 8:25138f7b9309 | 1 | #include "mbed.h" |
| andcor02 | 8:25138f7b9309 | 2 | #include "hcsr04.h" |
| andcor02 | 8:25138f7b9309 | 3 | |
| andcor02 | 8:25138f7b9309 | 4 | |
| andcor02 | 8:25138f7b9309 | 5 | DigitalOut myled(LED1); |
| VPKD1669 | 9:e703afddc87e | 6 | Serial pc(USBTX,USBRX); |
| VPKD1669 | 9:e703afddc87e | 7 | HCSR04 usensor(D8,D12); |
| andcor02 | 8:25138f7b9309 | 8 | unsigned int dist; |
| VPKD1669 | 9:e703afddc87e | 9 | DigitalOut GREEN(D13); |
| VPKD1669 | 9:e703afddc87e | 10 | DigitalOut BLUE(LED3); |
| VPKD1669 | 9:e703afddc87e | 11 | Timer dt; |
| VPKD1669 | 9:e703afddc87e | 12 | |
| andcor02 | 8:25138f7b9309 | 13 | int main() |
| andcor02 | 8:25138f7b9309 | 14 | { |
| VPKD1669 | 9:e703afddc87e | 15 | BLUE=1; |
| VPKD1669 | 9:e703afddc87e | 16 | pc.baud(9600); |
| VPKD1669 | 9:e703afddc87e | 17 | dt.start(); |
| andcor02 | 8:25138f7b9309 | 18 | while(1) { |
| andcor02 | 8:25138f7b9309 | 19 | usensor.start(); |
| andcor02 | 8:25138f7b9309 | 20 | wait_ms(500); |
| andcor02 | 8:25138f7b9309 | 21 | dist=usensor.get_dist_cm(); |
| VPKD1669 | 9:e703afddc87e | 22 | printf("\n\r cm:%ld",dist); |
| VPKD1669 | 9:e703afddc87e | 23 | if (dist>1 and dist<=20) |
| VPKD1669 | 9:e703afddc87e | 24 | { |
| VPKD1669 | 9:e703afddc87e | 25 | GREEN = !GREEN; |
| VPKD1669 | 9:e703afddc87e | 26 | } |
| VPKD1669 | 9:e703afddc87e | 27 | else |
| VPKD1669 | 9:e703afddc87e | 28 | { |
| VPKD1669 | 9:e703afddc87e | 29 | BLUE=0; |
| VPKD1669 | 9:e703afddc87e | 30 | } |
| andcor02 | 8:25138f7b9309 | 31 | |
| andcor02 | 8:25138f7b9309 | 32 | } |
| andcor02 | 8:25138f7b9309 | 33 | } |