KX022 Accelerometer library

Dependents:   LazuriteGraph_Hello KX022_Hello GR-PEACH_IoT_Platform_HTTP_sample

Embed: (wiki syntax)

« Back to documentation index

KX022 Class Reference

KX022 Class Reference

KX022 accelerometer example. More...

#include <KX022.h>

Public Member Functions

 KX022 (PinName sda, PinName scl, int addr=KX022_DEFAULT_SLAVE_ADDRESS)
 KX022 constructor.
 KX022 (I2C &i2c_obj, int addr=KX022_DEFAULT_SLAVE_ADDRESS)
 Create a KX022 instance which is connected to specified I2C pins with specified address.
 ~KX022 ()
 KX022 destructor.
void initialize (void)
 Initializa KX022 sensor.
float getAccX ()
 Get X axis acceleration.
float getAccY ()
 Get Y axis acceleration.
float getAccZ ()
 Get Z axis acceleration.
void getAccAllAxis (float *res)
 Get XYZ axis acceleration.

Detailed Description

KX022 accelerometer example.

 #include "mbed.h"
 #include "KX022.h"

 int main(void) {

 KX022 acc(I2C_SDA, I2C_SCL);
 PwmOut rled(LED_RED);
 PwmOut gled(LED_GREEN);
 PwmOut bled(LED_BLUE);

     while (true) {
         rled = 1.0 - abs(acc.getAccX());
         gled = 1.0 - abs(acc.getAccY());
         bled = 1.0 - abs(acc.getAccZ());
         wait(0.1);
     }
 }

Definition at line 81 of file KX022.h.


Constructor & Destructor Documentation

KX022 ( PinName  sda,
PinName  scl,
int  addr = KX022_DEFAULT_SLAVE_ADDRESS 
)

KX022 constructor.

Parameters:
sdaSDA pin
sdlSCL pin
addrslave address of the I2C peripheral (default: 0x3C)

Definition at line 33 of file KX022.cpp.

KX022 ( I2C &  i2c_obj,
int  addr = KX022_DEFAULT_SLAVE_ADDRESS 
)

Create a KX022 instance which is connected to specified I2C pins with specified address.

Parameters:
i2c_objI2C object (instance)
addrslave address of the I2C-bus peripheral (default: 0x3C)

Definition at line 38 of file KX022.cpp.

~KX022 (  )

KX022 destructor.

Definition at line 43 of file KX022.cpp.


Member Function Documentation

void getAccAllAxis ( float *  res )

Get XYZ axis acceleration.

Parameters:
resarray where acceleration data will be stored

Definition at line 95 of file KX022.cpp.

float getAccX (  )

Get X axis acceleration.

Returns:
X axis acceleration

Definition at line 80 of file KX022.cpp.

float getAccY (  )

Get Y axis acceleration.

Returns:
Y axis acceleration

Definition at line 85 of file KX022.cpp.

float getAccZ (  )

Get Z axis acceleration.

Returns:
Z axis acceleration

Definition at line 90 of file KX022.cpp.

void initialize ( void   )

Initializa KX022 sensor.

Configure sensor setting

Definition at line 47 of file KX022.cpp.