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
00001 #include "mbed.h" 00002 #include "TextLCD.h" 00003 00004 PinName pin_PSD = PC_1; 00005 00006 AnalogIn adc_PSD(pin_PSD); 00007 00008 // rs, rw, e, d0-d3 00009 TextLCD lcd(PB_12, PB_13, PB_14, PB_15, PA_9, PA_10, PA_11); 00010 00011 uint8_t Dist_cm(float volt); 00012 00013 int main() { 00014 00015 uint8_t dist; 00016 lcd.printf(" PSD Program\n"); 00017 lcd.printf(" Dist : [cm]"); 00018 while(1) { 00019 dist = Dist_cm(adc_PSD.read() * 3.3); 00020 lcd.locate(10, 1); 00021 lcd.printf("%2d", dist); 00022 wait(0.5); 00023 } 00024 } 00025 00026 uint8_t Dist_cm(float volt) 00027 { 00028 // float dist = 1.0/(0.0875 * volt - 0.00658); 00029 uint8_t result = 0; 00030 float dist = 1.0/(0.093 * volt - 0.009); 00031 if(dist < 0) 00032 result = 30; 00033 else 00034 result = dist; 00035 00036 if(result < 4) 00037 result = 4; 00038 else if(result > 30) 00039 result = 30; 00040 return result; 00041 }
Generated on Fri Jul 15 2022 15:03:35 by
