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: MaxSonar_EZ1_Analog TextLCD mbed
Fork of MaxSonar_EZ1_Analog by
main.cpp
00001 #include "mbed.h" 00002 #include "TextLCD.h" 00003 00004 // mbed -> EZ1 00005 // ----------- 00006 // VOUT -> +5 00007 // GND -> GND 00008 // p20 -> AN 00009 00010 00011 TextLCD lcd(p24, p26, p27, p28, p29, p30); // rs, e, d4-d7 00012 AnalogIn ain(p15); 00013 00014 LocalFileSystem local("local"); // Create the local filesystem under the name "local" 00015 00016 int main() { 00017 float adc, volts, grams; 00018 DigitalIn writebutton(p17); 00019 DigitalIn closebutton(p18); 00020 00021 FILE *fp = fopen("/local/out.txt", "w"); // Open "out.txt" on the local file system for writing 00022 00023 int writeenable = 0; 00024 int closefile = 0; 00025 00026 writebutton.mode(PullUp); 00027 closebutton.mode(PullUp); 00028 00029 while (1){ 00030 writeenable = writebutton.read(); 00031 closefile = closebutton.read(); 00032 00033 lcd.locate(0,0); 00034 adc = ain.read(); // read analog as a float 00035 volts = adc * 3.3; // convert to volts 00036 00037 lcd.printf("%8.3f volts\n", volts); 00038 00039 if(closefile == 0){ 00040 fclose(fp); 00041 break; 00042 } 00043 00044 if(writeenable == 0){ 00045 lcd.cls(); 00046 lcd.printf("Recording Voltage...\n\n"); 00047 fprintf(fp, "%8.3f volts\n", volts); 00048 lcd.printf("Done!\n\n"); 00049 wait(0.5); 00050 lcd.cls(); 00051 } 00052 00053 wait(0.05); // 20Hz update rate (once per 0.05 seconds) 00054 } 00055 } 00056 00057
Generated on Wed Jul 13 2022 03:36:07 by
1.7.2
