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.
Fork of Nucleo_read_analog_value by
main.cpp
00001 #include "mbed.h" 00002 #include "TextLCD.h" 00003 00004 TextLCD lcd(PC_11,PC_10,PC_0,PC_3,PC_1,PC_2); // RS, E, D4-D7 00005 Serial pc(USBTX,USBRX,115200); 00006 AnalogIn analog_value(PA_0); 00007 AnalogIn analog_value2(PA_1); 00008 Timer t; 00009 00010 int main() { 00011 pc.format(8,SerialBase::None,1); 00012 double meas, meas2, sum, sum2,count =0, range, range2, highscore = 0; 00013 bool lock = false; 00014 lcd.cls(); 00015 lcd.printf("Welcome to Speed Testing!"); 00016 00017 while(1) { 00018 t.reset(); 00019 meas = analog_value.read() * 3300; // Converts and read the analog input value (value from 0.0 to 1.0) 00020 // Change the value to be in the 0 to 3300 range 00021 meas2 = analog_value2.read() * 3300; 00022 00023 count++; 00024 sum+=meas; 00025 range=sum/count; 00026 sum2+=meas2; 00027 range2=sum2/count; 00028 00029 if(range > meas) 00030 range -= 100.0; 00031 if(range2 > meas2) 00032 range2 -= 100.0; 00033 00034 while(analog_value.read() * 3300 < range && analog_value2.read() * 3300 < range2); 00035 if (meas < range && meas2 > range2 && !lock) { // If the value is greater than 2V then switch the LED on 00036 lock = true; 00037 t.start(); 00038 while(analog_value2.read() * 3300 > range2); 00039 t.stop(); 00040 lcd.cls(); 00041 double time = t.read(); 00042 double speed = 7 / time; 00043 /* 00044 if(speed > highscore){ 00045 highscore = speed; 00046 lcd.printf("!!!New record!!!"); 00047 00048 }*/ 00049 pc.printf("%f s\n", time); 00050 pc.printf("%f cm/s\n", speed); 00051 00052 pc.printf("measure1 = %.0f mV, range1 = %.0f mV\n", meas, range); 00053 pc.printf("measure2 = %.0f mV, range2 = %.0f mV\n", meas2, range2); 00054 00055 lcd.locate(0,0); 00056 lcd.printf("%f s", time); 00057 lcd.locate(0,1); 00058 lcd.printf("%f cm/s", speed); 00059 lock = false; 00060 } 00061 } 00062 } 00063 00064 void animation(){ 00065 lcd.locate(0,1); 00066 lcd.printf("!*!*!*!*!*!*!*!*"); 00067 wait(0.5); 00068 lcd.locate(0,1); 00069 lcd.printf("~!~!~!~!~!~!~!~!"); 00070 wait(0.5); 00071 lcd.locate(0,1); 00072 lcd.printf("!~!~!~!~!~!~!~!~"); 00073 wait(0.5); 00074 lcd.locate(0,1); 00075 lcd.printf("~!~!~!~!~!~!~!~!"); 00076 wait(0.5); 00077 lcd.locate(0,1); 00078 lcd.printf("!~!~!~!~!~!~!~!~"); 00079 wait(0.5); 00080 lcd.locate(0,1); 00081 lcd.printf("~!~!~!~!~!~!~!~!"); 00082 wait(0.5); 00083 lcd.locate(0,1); 00084 lcd.printf("!~!~!~!~!~!~!~!~"); 00085 wait(0.5); 00086 lcd.locate(0,1); 00087 lcd.printf("~!~!~!~!~!~!~!~!"); 00088 lcd.cls(); 00089 }
Generated on Mon Jul 25 2022 17:12:54 by
1.7.2
