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
- Committer:
- bredeh
- Date:
- 2016-04-27
- Revision:
- 5:c0ceed1cbd3e
- Parent:
- 4:3fdf1cba912c
- Child:
- 6:86df4b837fa2
File content as of revision 5:c0ceed1cbd3e:
#include "mbed.h" #include "SRF05.h" #define MAX 30 #define INTERVALL (MAX/10) SRF05 srf(p17, p18); DigitalOut TriggerPin(p17); //Sender signal DigitalOut myled(LED1); DigitalIn EchoPin(p18); //Mottar signal DigitalIn Br(p15); BusOut bar(p21,p22,p23,p24,p25,p26,p27,p28, p29, p30); Serial pc(USBTX, USBRX); int valg; int start; int tall; int t; int verdi[11] = {1023, 511, 255, 127, 63, 31, 15, 7, 3, 1, 0}; float avstand; float distance; //variable for lagring og utrening av avstand. Timer echo; //Timer for avlesing av echosignal. //Sender ut ett trigger signal på 10us void triggerfunc() { TriggerPin = 1; wait_us(10); TriggerPin = 0; } main() { pc.printf("Tast 1 for avstandsmaaling: \n "); pc.printf("Tast 2 for bevegelsesmaaling: \n "); pc.printf("Tast 3 for hastighetsmaaling: \n "); pc.scanf("%d",&valg); int meny=valg; switch (meny) { case 1: while(1) { printf("Distance = %.1f\n\r", srf.read()); for(int i = 0; i < 11; i++) { float temp = srf.read(); if (temp < (MAX - INTERVALL*i) && temp > (MAX - INTERVALL*(i+1))) { bar = verdi[i]; } } wait(0.05); } case 2: float tiden; while(1) { triggerfunc(); while(!EchoPin); echo.start(); while(EchoPin); echo.stop(); if(EchoPin==0) { if(tiden==!echo.read_ms()) { pc.printf("Bevegelse \n"); } tiden=echo.read_ms(); echo.reset(); wait(0.01); } } case 3: float hastighet1; float hastighet2; float fart; Timer tid1; Timer tid2; while(1) { tid1.start(); hastighet1=srf.read(); wait(0.1); hastighet2=srf.read(); tid1.stop(); fart =( hastighet1-hastighet2 )/tid1.read(); printf("farten til objektet er : %.2f \n",fart); tid1.reset(); } } }