![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
private
Dependencies: ADXL345 FATFileSystem LPS331_SPI mbed
main.cpp@2:6c4273f2f7ed, 2017-09-16 (annotated)
- Committer:
- obaratakahiro
- Date:
- Sat Sep 16 05:24:37 2017 +0000
- Revision:
- 2:6c4273f2f7ed
- Parent:
- 1:9dc9b228c5b7
private
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
obaratakahiro | 2:6c4273f2f7ed | 1 | #include "mbed.h" |
obaratakahiro | 0:e9f20ea63046 | 2 | #include "SDFileSystem.h" |
obaratakahiro | 0:e9f20ea63046 | 3 | #include "LPS331_SPI.h" |
obaratakahiro | 1:9dc9b228c5b7 | 4 | #include "ADXL345.h" |
obaratakahiro | 2:6c4273f2f7ed | 5 | /*do include*/ |
obaratakahiro | 2:6c4273f2f7ed | 6 | DigitalOut myled(LED1);/*dp28 no LED*/ |
obaratakahiro | 2:6c4273f2f7ed | 7 | LPS331_SPI press(dp2, dp1, dp6, dp26);/*pressure no sengen*/ |
obaratakahiro | 2:6c4273f2f7ed | 8 | SDFileSystem sd(dp2, dp1, dp6, dp17, "sd"); /**/ |
obaratakahiro | 2:6c4273f2f7ed | 9 | AnalogIn sensor(dp4); |
obaratakahiro | 2:6c4273f2f7ed | 10 | ADXL345 accelerometer(dp2,dp1,dp6,dp25); |
obaratakahiro | 2:6c4273f2f7ed | 11 | Serial pc(USBTX,USBRX); |
obaratakahiro | 2:6c4273f2f7ed | 12 | /*sengensuru*/ |
obaratakahiro | 0:e9f20ea63046 | 13 | |
obaratakahiro | 0:e9f20ea63046 | 14 | int main() |
obaratakahiro | 0:e9f20ea63046 | 15 | { |
obaratakahiro | 2:6c4273f2f7ed | 16 | int readings[3] = {0,0,0}; |
obaratakahiro | 1:9dc9b228c5b7 | 17 | accelerometer.setPowerControl(0x00); |
obaratakahiro | 1:9dc9b228c5b7 | 18 | accelerometer.setDataFormatControl(0x0B); |
obaratakahiro | 1:9dc9b228c5b7 | 19 | accelerometer.setDataRate(ADXL345_3200HZ); |
obaratakahiro | 1:9dc9b228c5b7 | 20 | accelerometer.setPowerControl(0x08); |
obaratakahiro | 2:6c4273f2f7ed | 21 | |
obaratakahiro | 2:6c4273f2f7ed | 22 | |
obaratakahiro | 0:e9f20ea63046 | 23 | press.quickStart(); |
obaratakahiro | 0:e9f20ea63046 | 24 | |
obaratakahiro | 2:6c4273f2f7ed | 25 | int cl; |
obaratakahiro | 2:6c4273f2f7ed | 26 | int pr; |
obaratakahiro | 2:6c4273f2f7ed | 27 | |
obaratakahiro | 2:6c4273f2f7ed | 28 | FILE *fp = fopen("/sd/sdtest.txt","a"); |
obaratakahiro | 2:6c4273f2f7ed | 29 | if (fp == NULL) { |
obaratakahiro | 2:6c4273f2f7ed | 30 | printf("fopen error\n"); |
obaratakahiro | 2:6c4273f2f7ed | 31 | |
obaratakahiro | 2:6c4273f2f7ed | 32 | } |
obaratakahiro | 2:6c4273f2f7ed | 33 | pr = fprintf(fp, "START"); |
obaratakahiro | 2:6c4273f2f7ed | 34 | if (pr < 0){ |
obaratakahiro | 2:6c4273f2f7ed | 35 | printf("fprintf error\n"); |
obaratakahiro | 2:6c4273f2f7ed | 36 | } |
obaratakahiro | 2:6c4273f2f7ed | 37 | |
obaratakahiro | 2:6c4273f2f7ed | 38 | cl = fclose(fp); |
obaratakahiro | 2:6c4273f2f7ed | 39 | if(cl == EOF){ |
obaratakahiro | 2:6c4273f2f7ed | 40 | printf("fclose error\n"); |
obaratakahiro | 2:6c4273f2f7ed | 41 | } |
obaratakahiro | 2:6c4273f2f7ed | 42 | |
obaratakahiro | 1:9dc9b228c5b7 | 43 | |
obaratakahiro | 0:e9f20ea63046 | 44 | while(1){ |
obaratakahiro | 1:9dc9b228c5b7 | 45 | float ain = sensor; |
obaratakahiro | 0:e9f20ea63046 | 46 | float pressure; |
obaratakahiro | 1:9dc9b228c5b7 | 47 | accelerometer.getOutput(readings); |
obaratakahiro | 0:e9f20ea63046 | 48 | pressure = press.getPressure(); |
obaratakahiro | 1:9dc9b228c5b7 | 49 | ain = (ain * 3.3 - 0.6) / 0.01; |
obaratakahiro | 0:e9f20ea63046 | 50 | |
obaratakahiro | 2:6c4273f2f7ed | 51 | FILE *fp = fopen("/sd/sdtest.txt","a"); |
obaratakahiro | 2:6c4273f2f7ed | 52 | if (fp == NULL) { |
obaratakahiro | 2:6c4273f2f7ed | 53 | printf("fopen error\n"); |
obaratakahiro | 2:6c4273f2f7ed | 54 | |
obaratakahiro | 2:6c4273f2f7ed | 55 | } |
obaratakahiro | 2:6c4273f2f7ed | 56 | |
obaratakahiro | 2:6c4273f2f7ed | 57 | pr = fprintf(fp, "%f\r\n%f\r\n%i\r\n%i\r\n%i\r\n",pressure,ain,(int16_t)readings[0],(int16_t)readings[1],(int16_t)readings[2]); |
obaratakahiro | 2:6c4273f2f7ed | 58 | if (pr < 0){ |
obaratakahiro | 2:6c4273f2f7ed | 59 | printf("fprintf error\n"); |
obaratakahiro | 2:6c4273f2f7ed | 60 | |
obaratakahiro | 2:6c4273f2f7ed | 61 | } |
obaratakahiro | 2:6c4273f2f7ed | 62 | |
obaratakahiro | 2:6c4273f2f7ed | 63 | printf("%f\r\n%f\r\n%i\r\n%i\r\n%i\r\n",pressure,ain,(int16_t)readings[0],(int16_t)readings[1],(int16_t)readings[2]); |
obaratakahiro | 2:6c4273f2f7ed | 64 | |
obaratakahiro | 2:6c4273f2f7ed | 65 | cl = fclose(fp); |
obaratakahiro | 2:6c4273f2f7ed | 66 | if(cl == EOF){ |
obaratakahiro | 2:6c4273f2f7ed | 67 | printf("fclose error\n"); |
obaratakahiro | 2:6c4273f2f7ed | 68 | |
obaratakahiro | 2:6c4273f2f7ed | 69 | } |
obaratakahiro | 2:6c4273f2f7ed | 70 | |
obaratakahiro | 2:6c4273f2f7ed | 71 | free(fp); |
obaratakahiro | 2:6c4273f2f7ed | 72 | |
obaratakahiro | 2:6c4273f2f7ed | 73 | myled = !myled; |
obaratakahiro | 2:6c4273f2f7ed | 74 | wait(0.1); |
obaratakahiro | 0:e9f20ea63046 | 75 | } |
obaratakahiro | 0:e9f20ea63046 | 76 | } |