joe carter
/
nitrocarproject
main_programs/main3.h@0:960b355eaa84, 2010-08-20 (annotated)
- Committer:
- joe
- Date:
- Fri Aug 20 11:18:40 2010 +0000
- Revision:
- 0:960b355eaa84
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
joe | 0:960b355eaa84 | 1 | #include "mbed.h" |
joe | 0:960b355eaa84 | 2 | #include "TextLCD.h" |
joe | 0:960b355eaa84 | 3 | #include "Counter.h" |
joe | 0:960b355eaa84 | 4 | #include "LIS302.h" |
joe | 0:960b355eaa84 | 5 | #include "MSCFileSystem.h" |
joe | 0:960b355eaa84 | 6 | #include "Servo.h" |
joe | 0:960b355eaa84 | 7 | |
joe | 0:960b355eaa84 | 8 | Servo myservo(p21); |
joe | 0:960b355eaa84 | 9 | LIS302 acc (p5,p6,p7,p8); |
joe | 0:960b355eaa84 | 10 | DigitalIn enable(p20); |
joe | 0:960b355eaa84 | 11 | DigitalOut LIS302(LIS302); |
joe | 0:960b355eaa84 | 12 | DigitalOut led(LED1); |
joe | 0:960b355eaa84 | 13 | #define TICK_PERIOD 1.0 |
joe | 0:960b355eaa84 | 14 | MSCFileSystem fs("fs"); |
joe | 0:960b355eaa84 | 15 | |
joe | 0:960b355eaa84 | 16 | Counter counter(p18); |
joe | 0:960b355eaa84 | 17 | |
joe | 0:960b355eaa84 | 18 | |
joe | 0:960b355eaa84 | 19 | Ticker tick; |
joe | 0:960b355eaa84 | 20 | |
joe | 0:960b355eaa84 | 21 | Timer t; |
joe | 0:960b355eaa84 | 22 | int tick_active = 0; |
joe | 0:960b355eaa84 | 23 | |
joe | 0:960b355eaa84 | 24 | void dotick (void) { |
joe | 0:960b355eaa84 | 25 | tick_active = 1; |
joe | 0:960b355eaa84 | 26 | } |
joe | 0:960b355eaa84 | 27 | int rpm_counter=0; |
joe | 0:960b355eaa84 | 28 | int main() { |
joe | 0:960b355eaa84 | 29 | |
joe | 0:960b355eaa84 | 30 | TextLCD lcd(p24, p25, p26, p27, p28, p29, p30); // rs, rw, e, d0, d1, d2, d3 |
joe | 0:960b355eaa84 | 31 | FILE *fp = fopen("/fs/cardata.csv","w"); |
joe | 0:960b355eaa84 | 32 | fprintf(fp, "RPM,X,Y,Z\n"); |
joe | 0:960b355eaa84 | 33 | tick.attach(dotick,1.0); |
joe | 0:960b355eaa84 | 34 | while (1) { |
joe | 0:960b355eaa84 | 35 | if (enable) { |
joe | 0:960b355eaa84 | 36 | t.start(); |
joe | 0:960b355eaa84 | 37 | while (enable) { |
joe | 0:960b355eaa84 | 38 | |
joe | 0:960b355eaa84 | 39 | while (tick_active == 0) {} |
joe | 0:960b355eaa84 | 40 | rpm_counter = counter.read(); |
joe | 0:960b355eaa84 | 41 | counter.reset(); |
joe | 0:960b355eaa84 | 42 | led = !led; |
joe | 0:960b355eaa84 | 43 | fprintf(fp,"%d,%.2f,%.2f,%.2f\n",60*rpm_counter,acc.x(),acc.y(),acc.z()); |
joe | 0:960b355eaa84 | 44 | wait (0.1); |
joe | 0:960b355eaa84 | 45 | tick_active = 0; |
joe | 0:960b355eaa84 | 46 | |
joe | 0:960b355eaa84 | 47 | } |
joe | 0:960b355eaa84 | 48 | if (!enable) |
joe | 0:960b355eaa84 | 49 | t.stop(); |
joe | 0:960b355eaa84 | 50 | fprintf(fp,"this run lasted %f seconds \n", t.read()); |
joe | 0:960b355eaa84 | 51 | fprintf(fp,"off,off,off,off"); |
joe | 0:960b355eaa84 | 52 | fclose(fp); |
joe | 0:960b355eaa84 | 53 | } |
joe | 0:960b355eaa84 | 54 | } |
joe | 0:960b355eaa84 | 55 | |
joe | 0:960b355eaa84 | 56 | } |