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 DRV88255 TextLCD Ping mbed-rtos
ProximityController.cpp
00001 #include "ProximityController.h" 00002 #include "SensorAlarmController.h" 00003 00004 static Ping pinger(p30); 00005 static DigitalOut alarmled(LED3); 00006 00007 void ProximityController::update() { 00008 int range; 00009 00010 pinger.Send(); 00011 Thread::wait(30); 00012 range = pinger.Read_cm()/ 2; 00013 this->distance = (float)range; 00014 00015 printf("Read distance: %.3f\r\n", distance); 00016 00017 if(distance < 0.01) { 00018 SensorAlarmController::buzzOnce(); 00019 setLed(true); 00020 } else { 00021 setLed(false); 00022 } 00023 } 00024 00025 float ProximityController::getDistance() { 00026 return this->distance; 00027 } 00028 00029 float ProximityController::getValue() { 00030 if(distance < 0.01) { 00031 this->volume = -1.0f; 00032 } else { 00033 this->volume = (DISTANCE_TO_BASE - this->distance) * 76.92f; 00034 } 00035 00036 return this->volume; 00037 } 00038 00039 std::string ProximityController::getName() { 00040 return "ProximityController"; 00041 } 00042 00043 void ProximityController::setLed(bool value){ 00044 if (value) alarmled = 1; 00045 if (!value) alarmled = 0; 00046 }
Generated on Tue Jul 12 2022 18:59:29 by
1.7.2