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
- Committer:
- VPKD1669
- Date:
- 2019-12-06
- Revision:
- 9:e703afddc87e
- Parent:
- 8:25138f7b9309
File content as of revision 9:e703afddc87e:
#include "mbed.h"
#include "hcsr04.h"
DigitalOut myled(LED1);
Serial pc(USBTX,USBRX);
HCSR04 usensor(D8,D12);
unsigned int dist;
DigitalOut GREEN(D13);
DigitalOut BLUE(LED3);
Timer dt;
int main()
{
BLUE=1;
pc.baud(9600);
dt.start();
while(1) {
usensor.start();
wait_ms(500);
dist=usensor.get_dist_cm();
printf("\n\r cm:%ld",dist);
if (dist>1 and dist<=20)
{
GREEN = !GREEN;
}
else
{
BLUE=0;
}
}
}