燃焼ロガーのやつ
Dependencies: SDFileSystem mbed
Diff: main.cpp
- Revision:
- 0:63af8ff5b7d7
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Thu Mar 08 07:21:23 2018 +0000 @@ -0,0 +1,66 @@ +#include "mbed.h" +#include "SDFileSystem.h" + +Serial pc(USBTX,USBRX); +SDFileSystem sd(p5,p6,p7,p8,"sd"); +Ticker ADtimer; +AnalogIn amp1(p15); +AnalogIn amp2(p19); +AnalogIn amp3(p20); +DigitalOut led1(LED1); +DigitalOut led2(LED2); +DigitalOut led3(LED3); +DigitalOut led4(LED4); + +unsigned short a_val1[500][5]; +unsigned short a_val2[500][5]; +unsigned short a_val3[500][5]; +unsigned int count[500][5]; +unsigned int count1 = 0; +unsigned short gyo=0,retu=0,sdretu1,sdretu2,flag=0; + +void adread() +{ + count1++; + a_val1[gyo][retu] = amp1.read_u16() >> 4; + a_val2[gyo][retu] = amp2.read_u16() >> 4; + a_val3[gyo][retu] = amp3.read_u16() >> 4; + count[gyo][retu] = count1; + gyo++; + + if(gyo == 500){ + flag = 1; + gyo = 0; + sdretu1 = retu; + retu++; + if(retu == 5) + retu = 0; + } + + if((count1%1000)==0) pc.printf("%d,%d,%d\n",a_val1[gyo][retu],a_val2[gyo][retu],a_val3[gyo][retu]); +} + +int main() { + led1 = 1; + pc.printf("Start up!\r\n"); + ADtimer.attach(&adread,0.001); + + while(1) { + if(flag == 1){ + flag = 0; + sdretu2 = sdretu1; + led2 = 1; + FILE *fp = fopen("/sd/sd.csv","a"); + if(fp == NULL) + led4 = 1; + else + led2 = 1; + for(int i=0;i<500;i++){ + if(count[i][sdretu2]==1) fprintf(fp, "count, loadcell, pressure1, pressure2\n"); + fprintf(fp, "%d,%d,%d,%d\n",count[i][sdretu2],a_val1[i][sdretu2],a_val2[i][sdretu2],a_val3[i][sdretu2]); + } + fclose(fp); + led2 = 0; + } + } +} \ No newline at end of file