MPU6050のサンプルプログラム2

Dependencies:   ConfigFile SDFileSystem mbed

Fork of LAURUS_program by LAURUS

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers LPS25H.cpp Source File

LPS25H.cpp

00001 //**********************
00002 // LPS25H.cpp for mbed
00003 //
00004 // LPS25H lps25h(P0_5,P0_4);
00005 // or
00006 // I2C i2c(P0_5,P0_4);
00007 // LPS25H lps25h(i2c);
00008 //
00009 // (C)Copyright 2014 All rights reserved by Y.Onodera
00010 // http://einstlab.web.fc2.com
00011 //**********************
00012 
00013 #include "mbed.h"
00014 #include "LPS25H.h"
00015 
00016 /*LPS25H::LPS25H (PinName sda, PinName scl) : _i2c(sda, scl) {
00017     init();
00018 }*/
00019 LPS25H::LPS25H (I2C* p_i2c) : _i2c(p_i2c) {
00020     init();
00021 }
00022 
00023 void LPS25H::put(unsigned char a, unsigned char b)
00024 {
00025     buf[0]=a;
00026     buf[1]=b;
00027     _i2c->write(LPS25H_ADDR, buf, 2);
00028 }
00029 
00030 
00031 void LPS25H::get(unsigned char a)
00032 {
00033     buf[0] = a;
00034     _i2c->write(LPS25H_ADDR, buf, 1, true); // no stop, repeated
00035     _i2c->read( LPS25H_ADDR, buf, 1);
00036 
00037 }
00038 
00039 long LPS25H::pressure()
00040 {
00041 
00042     // XL first and H last
00043     // get press_xl
00044     get(LPS25H_PRESS_OUT_XL);
00045     press.byte.LB=buf[0];
00046     // get tpress_low
00047     get(LPS25H_PRESS_OUT_L);
00048     press.byte.HB=buf[0];
00049     // get press_high
00050     get(LPS25H_PRESS_OUT_H);
00051     press.byte.UB=buf[0];
00052     return press.Val;
00053  
00054     // hPa = press.Val / 4096
00055     // Pa = press.Val / 40.96   
00056 }
00057 
00058 
00059 short LPS25H::temperature()
00060 {
00061 
00062     // L first and H last
00063     // get tpress_low
00064     get(LPS25H_TEMP_OUT_L);
00065     temp.byte.LB=buf[0];
00066     // get press_high
00067     get(LPS25H_TEMP_OUT_H);
00068     temp.byte.HB=buf[0];
00069     return temp.S;
00070  
00071     // C = 42.5 + temp.S / 480
00072     // range:0 to 80C
00073     // accuracy:+-2C
00074 }
00075 
00076 
00077 void LPS25H::init()
00078 {
00079     // Resolution config
00080     put(LPS25H_RES_CONF, 0x0A);
00081     // FIFO 8samples moving average
00082     put(LPS25H_FIFO_CTRL, 0xC7);
00083     // FIFO Enable
00084     put(LPS25H_CTRL_REG2, 0x40);
00085     // Power ON Cycle=12.5Hz
00086     put(LPS25H_CTRL_REG1, 0xB0);
00087 }
00088 
00089