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.
Fork of Ultralydsensor by
Brede.cpp@1:cdf97a56d4d4, 2016-04-01 (annotated)
- Committer:
- bredeh
- Date:
- Fri Apr 01 09:42:39 2016 +0000
- Revision:
- 1:cdf97a56d4d4
- Parent:
- 0:27c5b713c538
- Child:
- 2:c4eb242c1b43
sas
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| Bjorken | 0:27c5b713c538 | 1 | #include "mbed.h" |
| Bjorken | 0:27c5b713c538 | 2 | |
| bredeh | 1:cdf97a56d4d4 | 3 | DigitalOut TriggerPin(p17); //Sender signal |
| bredeh | 1:cdf97a56d4d4 | 4 | DigitalOut EchoPin(p18); //Motar signal |
| bredeh | 1:cdf97a56d4d4 | 5 | DigitalIn Br(p15); |
| bredeh | 1:cdf97a56d4d4 | 6 | DigitalOut myled(LED1); |
| bredeh | 1:cdf97a56d4d4 | 7 | int valg; |
| bredeh | 1:cdf97a56d4d4 | 8 | float tid; |
| bredeh | 1:cdf97a56d4d4 | 9 | Timer timer; |
| bredeh | 1:cdf97a56d4d4 | 10 | Serial pc(USBTX, USBRX); |
| bredeh | 1:cdf97a56d4d4 | 11 | |
| bredeh | 1:cdf97a56d4d4 | 12 | Timer echo; //Timer for avlesing av echosignal. |
| bredeh | 1:cdf97a56d4d4 | 13 | |
| bredeh | 1:cdf97a56d4d4 | 14 | main() |
| bredeh | 1:cdf97a56d4d4 | 15 | { |
| bredeh | 1:cdf97a56d4d4 | 16 | pc.printf("Tast 1 for avstandsmaaling: "); |
| bredeh | 1:cdf97a56d4d4 | 17 | pc.printf("Tast 2 for bevegelsesmaaling: "); |
| bredeh | 1:cdf97a56d4d4 | 18 | pc.printf("Tast 3 for hastighetsmaaling: "); |
| bredeh | 1:cdf97a56d4d4 | 19 | pc.scanf("%d",&valg); |
| bredeh | 1:cdf97a56d4d4 | 20 | |
| bredeh | 1:cdf97a56d4d4 | 21 | |
| bredeh | 1:cdf97a56d4d4 | 22 | |
| bredeh | 1:cdf97a56d4d4 | 23 | } |
| bredeh | 1:cdf97a56d4d4 | 24 | |
| bredeh | 1:cdf97a56d4d4 | 25 | switch meny() |
| bredeh | 1:cdf97a56d4d4 | 26 | { |
| bredeh | 1:cdf97a56d4d4 | 27 | case 1: |
| bredeh | 1:cdf97a56d4d4 | 28 | timer.start() |
| bredeh | 1:cdf97a56d4d4 | 29 | triggerfunc(); |
| bredeh | 1:cdf97a56d4d4 | 30 | if(EchoPin==0) |
| bredeh | 1:cdf97a56d4d4 | 31 | { |
| bredeh | 1:cdf97a56d4d4 | 32 | timer.stop(); |
| bredeh | 1:cdf97a56d4d4 | 33 | pc.printf(" tiden lyden brukte er %f.4",timer.read();) |
| bredeh | 1:cdf97a56d4d4 | 34 | tid=timer.read()* 340) / 100 /2; |
| bredeh | 1:cdf97a56d4d4 | 35 | pc.printf(" Avstanden er %f.4",tid); |
| bredeh | 1:cdf97a56d4d4 | 36 | } |
| bredeh | 1:cdf97a56d4d4 | 37 | |
| bredeh | 1:cdf97a56d4d4 | 38 | |
| bredeh | 1:cdf97a56d4d4 | 39 | |
| bredeh | 1:cdf97a56d4d4 | 40 | |
| bredeh | 1:cdf97a56d4d4 | 41 | /* Sender ut ett trigger signal på 10us */ |
| bredeh | 1:cdf97a56d4d4 | 42 | void triggerfunc() |
| bredeh | 1:cdf97a56d4d4 | 43 | { |
| bredeh | 1:cdf97a56d4d4 | 44 | TriggerPin = 1; |
| bredeh | 1:cdf97a56d4d4 | 45 | wait(10u); |
| bredeh | 1:cdf97a56d4d4 | 46 | TriggerPin = 0; |
| bredeh | 1:cdf97a56d4d4 | 47 | } |
