![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
private
Dependencies: ADXL345 FATFileSystem LPS331_SPI mbed
main.cpp@1:9dc9b228c5b7, 2016-09-22 (annotated)
- Committer:
- obaratakahiro
- Date:
- Thu Sep 22 05:58:23 2016 +0000
- Revision:
- 1:9dc9b228c5b7
- Parent:
- 0:e9f20ea63046
- Child:
- 2:6c4273f2f7ed
????
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
obaratakahiro | 0:e9f20ea63046 | 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 | 0:e9f20ea63046 | 5 | DigitalOut myled(LED1); |
obaratakahiro | 0:e9f20ea63046 | 6 | LPS331_SPI press(dp2, dp1, dp6, dp26); |
obaratakahiro | 1:9dc9b228c5b7 | 7 | SDFileSystem sd(dp2, dp1, dp6, dp17, "sd"); |
obaratakahiro | 1:9dc9b228c5b7 | 8 | AnalogIn sensor (dp4); |
obaratakahiro | 1:9dc9b228c5b7 | 9 | ADXL345 accelerometer(dp2, dp1, dp6, dp25); |
obaratakahiro | 1:9dc9b228c5b7 | 10 | Serial pc(USBTX, USBRX); |
obaratakahiro | 0:e9f20ea63046 | 11 | |
obaratakahiro | 0:e9f20ea63046 | 12 | int main() |
obaratakahiro | 0:e9f20ea63046 | 13 | { |
obaratakahiro | 1:9dc9b228c5b7 | 14 | int readings[3] = {0, 0, 0}; |
obaratakahiro | 1:9dc9b228c5b7 | 15 | |
obaratakahiro | 1:9dc9b228c5b7 | 16 | accelerometer.setPowerControl(0x00); |
obaratakahiro | 1:9dc9b228c5b7 | 17 | accelerometer.setDataFormatControl(0x0B); |
obaratakahiro | 1:9dc9b228c5b7 | 18 | accelerometer.setDataRate(ADXL345_3200HZ); |
obaratakahiro | 1:9dc9b228c5b7 | 19 | accelerometer.setPowerControl(0x08); |
obaratakahiro | 0:e9f20ea63046 | 20 | press.quickStart(); |
obaratakahiro | 0:e9f20ea63046 | 21 | |
obaratakahiro | 0:e9f20ea63046 | 22 | int count; |
obaratakahiro | 1:9dc9b228c5b7 | 23 | |
obaratakahiro | 0:e9f20ea63046 | 24 | while(1){ |
obaratakahiro | 0:e9f20ea63046 | 25 | FILE *fp = fopen("/sd/sdtest.txt", "a"); |
obaratakahiro | 0:e9f20ea63046 | 26 | if(fp == NULL) { |
obaratakahiro | 0:e9f20ea63046 | 27 | error("Could not open file for write\n"); |
obaratakahiro | 0:e9f20ea63046 | 28 | } |
obaratakahiro | 1:9dc9b228c5b7 | 29 | float ain = sensor; |
obaratakahiro | 0:e9f20ea63046 | 30 | float pressure; |
obaratakahiro | 1:9dc9b228c5b7 | 31 | accelerometer.getOutput(readings); |
obaratakahiro | 0:e9f20ea63046 | 32 | pressure = press.getPressure(); |
obaratakahiro | 1:9dc9b228c5b7 | 33 | ain = (ain * 3.3 - 0.6) / 0.01; |
obaratakahiro | 0:e9f20ea63046 | 34 | |
obaratakahiro | 1:9dc9b228c5b7 | 35 | count = 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 | 0:e9f20ea63046 | 36 | if ( count < 0 ) { |
obaratakahiro | 0:e9f20ea63046 | 37 | printf("ファイルの書込みに失敗しました.\n"); |
obaratakahiro | 0:e9f20ea63046 | 38 | } |
obaratakahiro | 0:e9f20ea63046 | 39 | |
obaratakahiro | 0:e9f20ea63046 | 40 | |
obaratakahiro | 0:e9f20ea63046 | 41 | fclose(fp); |
obaratakahiro | 0:e9f20ea63046 | 42 | myled = !myled; |
obaratakahiro | 0:e9f20ea63046 | 43 | wait(0.5); |
obaratakahiro | 0:e9f20ea63046 | 44 | } |
obaratakahiro | 0:e9f20ea63046 | 45 | } |