Acceleration Datalogger
So I built a datalogger for temperature during the cold spell we had recently, and having just got the accelerometer written up, I now want to see how much of a boy racer I am (in my car, it is unlikely).
Anway, I am unashamedly using the "HowCold?" code base, cos it worked. The only change is that I have now added a coin cell to my breadboard, so I can just set the time one, and it keeps it :-)
#include "mbed.h" #include "LIS302.h" // Create the local filesystem under the name "local" LocalFileSystem local("local"); DigitalOut led1(LED1); DigitalOut led2(LED2); DigitalIn button(12); LIS302 acc(5, 6, 7, 8); Serial pc (USBTX,USBRX); float sample_delay = 0.1; int main() { while (!button) {} acc.range(1); led1 = 1; // Open "out.txt" on the local file system for writing FILE *fp = fopen("/local/Acceleration.csv", "w"); while (button) { led2 = !led2; // time,data<cr> fprintf(fp,"%02d/%02d/%02d %02d:%02d,%.2f,%.2f,%.2f\n",RTC_DOM,RTC_MONTH,RTC_YEAR,RTC_HOUR,RTC_MIN,acc.x(),acc.y(),acc.z()); pc.printf("%02d/%02d/%02d %02d:%02d,%.2f,%.2f,%.2f\n",RTC_DOM,RTC_MONTH,RTC_YEAR,RTC_HOUR,RTC_MIN,acc.x(),acc.y(),acc.z()); wait (sample_delay); } fclose(fp); led1 = 0; exit(0); }
