A program designed to get the distance from an SRF02 distance sensor and create an audible and visual indication of that distance with data logging capabilities.
Dependencies: N5110 PowerControl SRF02 mbed
Diff: main.cpp
- Revision:
- 3:4e8fb4fb54df
- Parent:
- 2:ebcfecb68cca
- Child:
- 4:0bd5c189f2f3
--- a/main.cpp Wed Apr 08 20:10:26 2015 +0000 +++ b/main.cpp Wed Apr 08 20:21:54 2015 +0000 @@ -1,7 +1,7 @@ // Distance Sensor Project // Main File "main.cpp" // Designed By Sam Russell (200773195) -// Date: 07/04/2015 || Version: 0.1b +// Date: 07/04/2015 || Version: 0.3a #include "main.h" @@ -34,13 +34,13 @@ setTimeFlag = 1; } -void writeDataToFile(char* data, float dataDistance) +void writeDataToFile(char* data, int dataDistance) { logLED = 1; // turn on LEDs for feedback pc.printf("Data Logged\n"); //DEBUG MESSAGE FILE *fp = fopen("/local/log.csv", "a"); // open 'log.txt' for appending // if the file doesn't exist it is created, if it exists, data is appended to the end - fprintf(fp,"%s %.2f\n",data,dataDistance); // print string to file + fprintf(fp,"%s %d\n",data,dataDistance); // print string to file fclose(fp); // close file } @@ -105,7 +105,7 @@ // format time into a string (time and date) strftime(buffer, 30 , "%R %d/%m/%y", localtime(&seconds)); // print over serial - pc.printf("%s , %.2f cm\n",buffer,distance); //print the temperature value and the date/time to the serial. + pc.printf("%s , %d cm\n",buffer,distance); //print the temperature value and the date/time to the serial. display.clear(); //Clear the display, updating bar graph. char buffer2[50]; // buffer2 is used to store the distance string. sprintf (buffer2, "%d cm", distance); //Composes a printf compatable string and stores the distance in the buffer2.