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 // #include "math.h" 00004 00005 TextLCD lcd(p24, p26, p27, p28, p29, p30); 00006 AnalogIn in(p20); 00007 AnalogOut out(p18); 00008 Ticker input; 00009 Ticker output; 00010 int freq; 00011 double t = 0.0 ; 00012 float d11 = 0.0, d12 =0.0 ; 00013 00014 void run(){ 00015 float data ; 00016 00017 data = in; 00018 lcd.locate(3,0); 00019 00020 if ( data < 0.1212){ 00021 freq = 0; 00022 lcd.putc(0xFE); 00023 lcd.putc(0xFE); 00024 }else if ( data < 0.181){ 00025 freq = 2093; 00026 lcd.putc(0xC4); 00027 lcd.putc(0xDE); 00028 }else if ( data < 0.242){ 00029 freq = 1976; 00030 lcd.putc(0xBC); 00031 lcd.putc(0xFE); 00032 }else if ( data < 0.333){ 00033 freq = 1760; 00034 lcd.putc(0xD7); 00035 lcd.putc(0xFE); 00036 }else if ( data < 0.394){ 00037 freq = 1568; 00038 lcd.putc(0xBF); 00039 lcd.putc(0xFE); 00040 }else if ( data < 0.485){ 00041 freq = 1397; 00042 lcd.putc(0xCC); 00043 lcd.putc(0xA7); 00044 }else if ( data < 0.697 ){ 00045 freq = 1319; 00046 lcd.putc(0xD0); 00047 lcd.putc(0xFE); 00048 }else if ( data < 0.85){ 00049 freq = 1175; 00050 lcd.putc(0xDA); 00051 lcd.putc(0xFE); 00052 }else{ 00053 freq = 1046; 00054 lcd.putc(0xC4); 00055 lcd.putc(0xDE); 00056 } 00057 00058 if ( 0.12 <= data){ 00059 float range = 26.663 * pow((data*3.3),-1.25); 00060 lcd.locate(0,1); 00061 lcd.printf("RANGE %4.1f[cm]",range); 00062 }else{ 00063 lcd.locate(0,1); 00064 lcd.printf("RANGE OVER! "); 00065 } 00066 } 00067 00068 void wave(){ 00069 float a; 00070 00071 if ( freq != 0 ){ 00072 a =0.5*sin(2.0 * 3.1415 * freq * t )+0.5; 00073 out = a; 00074 } 00075 if ( t > 1.0 ) t = 0.0 ; 00076 t=t+0.00005; 00077 } 00078 00079 int main() { 00080 input.attach(&run,0.5); 00081 output.attach_us(&wave,50); 00082 00083 while(1){ 00084 00085 } 00086 }
Generated on Thu Jul 14 2022 01:26:05 by
1.7.2