Shingo FUKUYA
/
Airio-Base_Grove_6Axis_OS5
Airio-Base test program using Mbed OS 5 .
main.cpp@0:be8ed55bdf37, 2019-07-16 (annotated)
- Committer:
- mbed_crane_elec
- Date:
- Tue Jul 16 21:24:32 2019 +0000
- Revision:
- 0:be8ed55bdf37
for OS 5
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbed_crane_elec | 0:be8ed55bdf37 | 1 | #include "mbed.h" |
mbed_crane_elec | 0:be8ed55bdf37 | 2 | #include "SDFileSystem.h" |
mbed_crane_elec | 0:be8ed55bdf37 | 3 | #include "LSM6DS3.h" |
mbed_crane_elec | 0:be8ed55bdf37 | 4 | |
mbed_crane_elec | 0:be8ed55bdf37 | 5 | //------------------------------------------------------------------------------- |
mbed_crane_elec | 0:be8ed55bdf37 | 6 | //Port Settings |
mbed_crane_elec | 0:be8ed55bdf37 | 7 | DigitalOut led1(LED1); |
mbed_crane_elec | 0:be8ed55bdf37 | 8 | DigitalOut led2(P1_13,0); |
mbed_crane_elec | 0:be8ed55bdf37 | 9 | //DigitalOut USB_CONNECT(P0_6,0); |
mbed_crane_elec | 0:be8ed55bdf37 | 10 | DigitalIn sw(P1_20); |
mbed_crane_elec | 0:be8ed55bdf37 | 11 | DigitalIn isp(P0_1); |
mbed_crane_elec | 0:be8ed55bdf37 | 12 | DigitalOut sd_en(P1_16, 1);//SD card power on/off control port. and ON default. |
mbed_crane_elec | 0:be8ed55bdf37 | 13 | //DigitalIn sd_dat3(P0_17); // 0x10 |
mbed_crane_elec | 0:be8ed55bdf37 | 14 | //DigitalIn sd_dat2(P1_22); // 0x08 |
mbed_crane_elec | 0:be8ed55bdf37 | 15 | //DigitalIn sd_dat1(P1_14); // 0x04 |
mbed_crane_elec | 0:be8ed55bdf37 | 16 | //DigitalIn sd_dat0(P0_22); // 0x02 |
mbed_crane_elec | 0:be8ed55bdf37 | 17 | //DigitalIn sd_cmd(P0_21); // 0x01 |
mbed_crane_elec | 0:be8ed55bdf37 | 18 | |
mbed_crane_elec | 0:be8ed55bdf37 | 19 | //------------------------------------------------------------------------------- |
mbed_crane_elec | 0:be8ed55bdf37 | 20 | // |
mbed_crane_elec | 0:be8ed55bdf37 | 21 | SDFileSystem fs(P0_21, P0_22, P1_15, P0_17, "sd"); // mosi(CMD), miso(DAT0), sclk(CLK), cs(DAT3) |
mbed_crane_elec | 0:be8ed55bdf37 | 22 | LSM6DS3 lsm(P0_5, P0_4, LSM6DS3_AG_I2C_ADDR(0) );//I2C ADDR 0x6A |
mbed_crane_elec | 0:be8ed55bdf37 | 23 | |
mbed_crane_elec | 0:be8ed55bdf37 | 24 | |
mbed_crane_elec | 0:be8ed55bdf37 | 25 | //------------------------------------------------------------------------------- |
mbed_crane_elec | 0:be8ed55bdf37 | 26 | // |
mbed_crane_elec | 0:be8ed55bdf37 | 27 | int main() |
mbed_crane_elec | 0:be8ed55bdf37 | 28 | { |
mbed_crane_elec | 0:be8ed55bdf37 | 29 | while(1) |
mbed_crane_elec | 0:be8ed55bdf37 | 30 | { |
mbed_crane_elec | 0:be8ed55bdf37 | 31 | led1 = 1; |
mbed_crane_elec | 0:be8ed55bdf37 | 32 | wait(0.2); |
mbed_crane_elec | 0:be8ed55bdf37 | 33 | led1 = 0; |
mbed_crane_elec | 0:be8ed55bdf37 | 34 | wait(0.2); |
mbed_crane_elec | 0:be8ed55bdf37 | 35 | |
mbed_crane_elec | 0:be8ed55bdf37 | 36 | if(sw == 0) |
mbed_crane_elec | 0:be8ed55bdf37 | 37 | { |
mbed_crane_elec | 0:be8ed55bdf37 | 38 | led2 = 0; |
mbed_crane_elec | 0:be8ed55bdf37 | 39 | } |
mbed_crane_elec | 0:be8ed55bdf37 | 40 | else |
mbed_crane_elec | 0:be8ed55bdf37 | 41 | { |
mbed_crane_elec | 0:be8ed55bdf37 | 42 | led2 = 1; |
mbed_crane_elec | 0:be8ed55bdf37 | 43 | } |
mbed_crane_elec | 0:be8ed55bdf37 | 44 | |
mbed_crane_elec | 0:be8ed55bdf37 | 45 | if(isp == 0) |
mbed_crane_elec | 0:be8ed55bdf37 | 46 | { |
mbed_crane_elec | 0:be8ed55bdf37 | 47 | FILE *fp = fopen("/sd/TEST_OS5.txt", "w"); |
mbed_crane_elec | 0:be8ed55bdf37 | 48 | if(fp != NULL) |
mbed_crane_elec | 0:be8ed55bdf37 | 49 | { |
mbed_crane_elec | 0:be8ed55bdf37 | 50 | lsm.begin(); |
mbed_crane_elec | 0:be8ed55bdf37 | 51 | for(int i = 0;i < 5;i++) |
mbed_crane_elec | 0:be8ed55bdf37 | 52 | { |
mbed_crane_elec | 0:be8ed55bdf37 | 53 | led2 = 0; |
mbed_crane_elec | 0:be8ed55bdf37 | 54 | wait(0.1); |
mbed_crane_elec | 0:be8ed55bdf37 | 55 | lsm.readGyro(); |
mbed_crane_elec | 0:be8ed55bdf37 | 56 | fprintf(fp,"gx:%f gy:%f gz:%f\r\n",lsm.gx ,lsm.gy ,lsm.gz); |
mbed_crane_elec | 0:be8ed55bdf37 | 57 | lsm.readAccel(); |
mbed_crane_elec | 0:be8ed55bdf37 | 58 | fprintf(fp,"ax:%f ay:%f az:%f\r\n",lsm.ax ,lsm.ay ,lsm.az); |
mbed_crane_elec | 0:be8ed55bdf37 | 59 | lsm.readTemp(); |
mbed_crane_elec | 0:be8ed55bdf37 | 60 | fprintf(fp,"temp:%f\r\n",lsm.temperature_c ); |
mbed_crane_elec | 0:be8ed55bdf37 | 61 | led2 = 1; |
mbed_crane_elec | 0:be8ed55bdf37 | 62 | wait(0.3); |
mbed_crane_elec | 0:be8ed55bdf37 | 63 | } |
mbed_crane_elec | 0:be8ed55bdf37 | 64 | fprintf(fp,"\r\n"); |
mbed_crane_elec | 0:be8ed55bdf37 | 65 | fclose(fp); |
mbed_crane_elec | 0:be8ed55bdf37 | 66 | free(fp); |
mbed_crane_elec | 0:be8ed55bdf37 | 67 | } |
mbed_crane_elec | 0:be8ed55bdf37 | 68 | } |
mbed_crane_elec | 0:be8ed55bdf37 | 69 | } |
mbed_crane_elec | 0:be8ed55bdf37 | 70 | } |