joe carter
/
nitrocarproject
Embed:
(wiki syntax)
Show/hide line numbers
main3.h
00001 #include "mbed.h" 00002 #include "TextLCD.h" 00003 #include "Counter.h" 00004 #include "LIS302.h" 00005 #include "MSCFileSystem.h" 00006 #include "Servo.h" 00007 00008 Servo myservo(p21); 00009 LIS302 acc (p5,p6,p7,p8); 00010 DigitalIn enable(p20); 00011 DigitalOut LIS302(LIS302); 00012 DigitalOut led(LED1); 00013 #define TICK_PERIOD 1.0 00014 MSCFileSystem fs("fs"); 00015 00016 Counter counter(p18); 00017 00018 00019 Ticker tick; 00020 00021 Timer t; 00022 int tick_active = 0; 00023 00024 void dotick (void) { 00025 tick_active = 1; 00026 } 00027 int rpm_counter=0; 00028 int main() { 00029 00030 TextLCD lcd(p24, p25, p26, p27, p28, p29, p30); // rs, rw, e, d0, d1, d2, d3 00031 FILE *fp = fopen("/fs/cardata.csv","w"); 00032 fprintf(fp, "RPM,X,Y,Z\n"); 00033 tick.attach(dotick,1.0); 00034 while (1) { 00035 if (enable) { 00036 t.start(); 00037 while (enable) { 00038 00039 while (tick_active == 0) {} 00040 rpm_counter = counter.read(); 00041 counter.reset(); 00042 led = !led; 00043 fprintf(fp,"%d,%.2f,%.2f,%.2f\n",60*rpm_counter,acc.x(),acc.y(),acc.z()); 00044 wait (0.1); 00045 tick_active = 0; 00046 00047 } 00048 if (!enable) 00049 t.stop(); 00050 fprintf(fp,"this run lasted %f seconds \n", t.read()); 00051 fprintf(fp,"off,off,off,off"); 00052 fclose(fp); 00053 } 00054 } 00055 00056 }
Generated on Wed Jul 13 2022 03:39:42 by 1.7.2