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.
Dependencies: mbed HCSR04 AutomationElements
Revision 7:667133e8fb42, committed 2020-12-15
- Comitter:
- jakobhz
- Date:
- Tue Dec 15 18:14:00 2020 +0000
- Parent:
- 6:bca0839e8295
- Commit message:
- ultrasonic sensor alarm system
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
mbed.bld | Show annotated file Show diff for this revision Revisions of this file |
diff -r bca0839e8295 -r 667133e8fb42 main.cpp --- a/main.cpp Sat Dec 10 08:28:06 2016 +0000 +++ b/main.cpp Tue Dec 15 18:14:00 2020 +0000 @@ -2,8 +2,11 @@ #include "HCSR04.h" #include "AutomationElements.h" +DigitalIn mypin(D4); +PwmOut Buzzer(D5); +DigitalOut myled(D7); Serial pc(USBTX, USBRX); -HCSR04 sensor(p5, p7); +HCSR04 sensor(D8, D9); float sampleTime = 0.5; PT1 filter(1, 2, sampleTime); Ticker ticker; @@ -23,9 +26,19 @@ while(!sensor.isNewDataReady()) { // wait for new data } - distance = sensor.getDistance_cm(); + float distance = sensor.getDistance_cm(); filter.in(distance); filteredDistance = filter.out(); pc.printf("%7.1f cm %7.1f cm\n\r", distance, filteredDistance); + + if(distance<10 && mypin == 1){ + pc.printf("intruder alert"); + myled = 1; + Buzzer = 1; + } + else{ + myled = 0; + Buzzer = 0; + } } } \ No newline at end of file
diff -r bca0839e8295 -r 667133e8fb42 mbed.bld --- a/mbed.bld Sat Dec 10 08:28:06 2016 +0000 +++ b/mbed.bld Tue Dec 15 18:14:00 2020 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/mbed_official/code/mbed/builds/9296ab0bfc11 \ No newline at end of file +https://os.mbed.com/users/mbed_official/code/mbed/builds/65be27845400 \ No newline at end of file