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-22
- Revision:
- 2:c4eb242c1b43
- Parent:
- 1:cdf97a56d4d4
- Child:
- 3:ed77f5925399
File content as of revision 2:c4eb242c1b43:
#include "mbed.h"
#include "SRF05.h"
SRF05 srf(p17, p18);
DigitalOut TriggerPin(p17); //Sender signal
DigitalIn EchoPin(p18); //Mottar signal
DigitalIn Br(p15);
DigitalOut myled(LED1);
int valg;
float avstand;
void flushSerialBuffer(void);
Serial pc(USBTX, USBRX);
BusOut bargraph(p21,p22,p23,p24,p25,p26,p27,p28, p29, p30);
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", srf.read());
bargraph=10*srf.read();
wait(0.5);
}
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();
}
}
/*void flushSerialBuffer(void)
{
while (pc.readable()) {
(void) pc.getc();
}
return;
*/
}
