
Test
Dependencies: MaxSonar_EZ1_Analog TextLCD mbed
Fork of MaxSonar_EZ1_Analog by
Revision 2:010f6e9e7174, committed 2017-03-03
- Comitter:
- moshi
- Date:
- Fri Mar 03 01:53:33 2017 +0000
- Parent:
- 1:7931088c5e05
- Commit message:
- Test program;
Changed in this revision
MaxSonar_EZ1_Analog.lib | Show annotated file Show diff for this revision Revisions of this file |
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 7931088c5e05 -r 010f6e9e7174 MaxSonar_EZ1_Analog.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MaxSonar_EZ1_Analog.lib Fri Mar 03 01:53:33 2017 +0000 @@ -0,0 +1,1 @@ +http://developer.mbed.org/users/hasimo/code/MaxSonar_EZ1_Analog/#7931088c5e05
diff -r 7931088c5e05 -r 010f6e9e7174 main.cpp --- a/main.cpp Wed Jul 23 10:33:12 2014 +0000 +++ b/main.cpp Fri Mar 03 01:53:33 2017 +0000 @@ -11,18 +11,46 @@ TextLCD lcd(p24, p26, p27, p28, p29, p30); // rs, e, d4-d7 AnalogIn ain(p15); +LocalFileSystem local("local"); // Create the local filesystem under the name "local" + int main() { - float adc, volts, inches, cm; + float adc, volts, grams; + DigitalIn writebutton(p17); + DigitalIn closebutton(p18); + + FILE *fp = fopen("/local/out.txt", "w"); // Open "out.txt" on the local file system for writing + + int writeenable = 0; + int closefile = 0; + + writebutton.mode(PullUp); + closebutton.mode(PullUp); while (1){ + writeenable = writebutton.read(); + closefile = closebutton.read(); + lcd.locate(0,0); adc = ain.read(); // read analog as a float volts = adc * 3.3; // convert to volts - inches = volts / (3.3 / 512.0); // 3.3V supply: 6.4mV per inch - cm = inches * 2.54; // inch to cm - lcd.printf("%8.3f cm\n", cm); - wait(0.05); // 20Hz update rate + lcd.printf("%8.3f volts\n", volts); + + if(closefile == 0){ + fclose(fp); + break; + } + + if(writeenable == 0){ + lcd.cls(); + lcd.printf("Recording Voltage...\n\n"); + fprintf(fp, "%8.3f volts\n", volts); + lcd.printf("Done!\n\n"); + wait(0.5); + lcd.cls(); + } + + wait(0.05); // 20Hz update rate (once per 0.05 seconds) } }