燃焼ロガーのやつ
Dependencies: SDFileSystem mbed
main.cpp@0:63af8ff5b7d7, 2018-03-08 (annotated)
- Committer:
- Aomolry
- Date:
- Thu Mar 08 07:21:23 2018 +0000
- Revision:
- 0:63af8ff5b7d7
??????
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Aomolry | 0:63af8ff5b7d7 | 1 | #include "mbed.h" |
Aomolry | 0:63af8ff5b7d7 | 2 | #include "SDFileSystem.h" |
Aomolry | 0:63af8ff5b7d7 | 3 | |
Aomolry | 0:63af8ff5b7d7 | 4 | Serial pc(USBTX,USBRX); |
Aomolry | 0:63af8ff5b7d7 | 5 | SDFileSystem sd(p5,p6,p7,p8,"sd"); |
Aomolry | 0:63af8ff5b7d7 | 6 | Ticker ADtimer; |
Aomolry | 0:63af8ff5b7d7 | 7 | AnalogIn amp1(p15); |
Aomolry | 0:63af8ff5b7d7 | 8 | AnalogIn amp2(p19); |
Aomolry | 0:63af8ff5b7d7 | 9 | AnalogIn amp3(p20); |
Aomolry | 0:63af8ff5b7d7 | 10 | DigitalOut led1(LED1); |
Aomolry | 0:63af8ff5b7d7 | 11 | DigitalOut led2(LED2); |
Aomolry | 0:63af8ff5b7d7 | 12 | DigitalOut led3(LED3); |
Aomolry | 0:63af8ff5b7d7 | 13 | DigitalOut led4(LED4); |
Aomolry | 0:63af8ff5b7d7 | 14 | |
Aomolry | 0:63af8ff5b7d7 | 15 | unsigned short a_val1[500][5]; |
Aomolry | 0:63af8ff5b7d7 | 16 | unsigned short a_val2[500][5]; |
Aomolry | 0:63af8ff5b7d7 | 17 | unsigned short a_val3[500][5]; |
Aomolry | 0:63af8ff5b7d7 | 18 | unsigned int count[500][5]; |
Aomolry | 0:63af8ff5b7d7 | 19 | unsigned int count1 = 0; |
Aomolry | 0:63af8ff5b7d7 | 20 | unsigned short gyo=0,retu=0,sdretu1,sdretu2,flag=0; |
Aomolry | 0:63af8ff5b7d7 | 21 | |
Aomolry | 0:63af8ff5b7d7 | 22 | void adread() |
Aomolry | 0:63af8ff5b7d7 | 23 | { |
Aomolry | 0:63af8ff5b7d7 | 24 | count1++; |
Aomolry | 0:63af8ff5b7d7 | 25 | a_val1[gyo][retu] = amp1.read_u16() >> 4; |
Aomolry | 0:63af8ff5b7d7 | 26 | a_val2[gyo][retu] = amp2.read_u16() >> 4; |
Aomolry | 0:63af8ff5b7d7 | 27 | a_val3[gyo][retu] = amp3.read_u16() >> 4; |
Aomolry | 0:63af8ff5b7d7 | 28 | count[gyo][retu] = count1; |
Aomolry | 0:63af8ff5b7d7 | 29 | gyo++; |
Aomolry | 0:63af8ff5b7d7 | 30 | |
Aomolry | 0:63af8ff5b7d7 | 31 | if(gyo == 500){ |
Aomolry | 0:63af8ff5b7d7 | 32 | flag = 1; |
Aomolry | 0:63af8ff5b7d7 | 33 | gyo = 0; |
Aomolry | 0:63af8ff5b7d7 | 34 | sdretu1 = retu; |
Aomolry | 0:63af8ff5b7d7 | 35 | retu++; |
Aomolry | 0:63af8ff5b7d7 | 36 | if(retu == 5) |
Aomolry | 0:63af8ff5b7d7 | 37 | retu = 0; |
Aomolry | 0:63af8ff5b7d7 | 38 | } |
Aomolry | 0:63af8ff5b7d7 | 39 | |
Aomolry | 0:63af8ff5b7d7 | 40 | if((count1%1000)==0) pc.printf("%d,%d,%d\n",a_val1[gyo][retu],a_val2[gyo][retu],a_val3[gyo][retu]); |
Aomolry | 0:63af8ff5b7d7 | 41 | } |
Aomolry | 0:63af8ff5b7d7 | 42 | |
Aomolry | 0:63af8ff5b7d7 | 43 | int main() { |
Aomolry | 0:63af8ff5b7d7 | 44 | led1 = 1; |
Aomolry | 0:63af8ff5b7d7 | 45 | pc.printf("Start up!\r\n"); |
Aomolry | 0:63af8ff5b7d7 | 46 | ADtimer.attach(&adread,0.001); |
Aomolry | 0:63af8ff5b7d7 | 47 | |
Aomolry | 0:63af8ff5b7d7 | 48 | while(1) { |
Aomolry | 0:63af8ff5b7d7 | 49 | if(flag == 1){ |
Aomolry | 0:63af8ff5b7d7 | 50 | flag = 0; |
Aomolry | 0:63af8ff5b7d7 | 51 | sdretu2 = sdretu1; |
Aomolry | 0:63af8ff5b7d7 | 52 | led2 = 1; |
Aomolry | 0:63af8ff5b7d7 | 53 | FILE *fp = fopen("/sd/sd.csv","a"); |
Aomolry | 0:63af8ff5b7d7 | 54 | if(fp == NULL) |
Aomolry | 0:63af8ff5b7d7 | 55 | led4 = 1; |
Aomolry | 0:63af8ff5b7d7 | 56 | else |
Aomolry | 0:63af8ff5b7d7 | 57 | led2 = 1; |
Aomolry | 0:63af8ff5b7d7 | 58 | for(int i=0;i<500;i++){ |
Aomolry | 0:63af8ff5b7d7 | 59 | if(count[i][sdretu2]==1) fprintf(fp, "count, loadcell, pressure1, pressure2\n"); |
Aomolry | 0:63af8ff5b7d7 | 60 | fprintf(fp, "%d,%d,%d,%d\n",count[i][sdretu2],a_val1[i][sdretu2],a_val2[i][sdretu2],a_val3[i][sdretu2]); |
Aomolry | 0:63af8ff5b7d7 | 61 | } |
Aomolry | 0:63af8ff5b7d7 | 62 | fclose(fp); |
Aomolry | 0:63af8ff5b7d7 | 63 | led2 = 0; |
Aomolry | 0:63af8ff5b7d7 | 64 | } |
Aomolry | 0:63af8ff5b7d7 | 65 | } |
Aomolry | 0:63af8ff5b7d7 | 66 | } |