Skip to content

Commit

Permalink
Adding the examples
Browse files Browse the repository at this point in the history
  • Loading branch information
rezaneam committed May 9, 2021
1 parent b26b415 commit 9e74386
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 1 deletion.
32 changes: 32 additions & 0 deletions examples/Basic.ino/Basic.ino.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#include <BMA400.h>
#include <Wire.h>

BMA400 bma400;

void setup()
{
// put your setup code here, to run once:
Serial.begin(115200);

Wire.begin(GPIO_NUM_21, GPIO_NUM_22, 400000);

if (bma400.Initialize(BMA400_ADDRESS_PRIMARY)) // Using the default Wire interface
{
printf("BMA400 Sensor successfully found\r\n");
bma400.Setup(
BMA400::power_mode_t::LOW_POWER,
BMA400::output_data_rate_t::Filter2_100Hz,
BMA400::acceleation_range_t::RANGE_4G);
}
else
printf("Error! no BMA400 sensor found\r\n");
}

void loop()
{
// put your main code here, to run repeatedly:
float acceleration[3] = {0};
bma400.ReadAcceleration(acceleration);
printf("Acceleration(g) [X, Y, Z] = %2.2f %2.2f %2.2f\r\n", acceleration[0], acceleration[1], acceleration[2]);
delay(1000);
}
32 changes: 32 additions & 0 deletions examples/BasicAutoAddressDetect/BasicAutoAddressDetect.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#include <Arduino.h>
#include <BMA400.h>
#include <Wire.h>

BMA400 bma400;
void setup()
{
// put your setup code here, to run once:
Serial.begin(115200);

Wire.begin(GPIO_NUM_21, GPIO_NUM_22, 400000);

if (bma400.Initialize()) // Automatically resolving the address
{
printf("BMA400 Sensor successfully found\r\n");
bma400.Setup(
BMA400::power_mode_t::NORMAL,
BMA400::output_data_rate_t::Filter1_048x_200Hz,
BMA400::acceleation_range_t::RANGE_4G);
}
else
printf("Error! no BMA400 sensor found\r\n");
}

void loop()
{
// put your main code here, to run repeatedly:
float acceleration[3] = {0};
bma400.ReadAcceleration(acceleration);
printf("Acceleration(g) [X, Y, Z] = %2.2f %2.2f %2.2f\r\n", acceleration[0], acceleration[1], acceleration[2]);
delay(1000);
}
32 changes: 32 additions & 0 deletions examples/BasicCustomInterface/BasicCustomInterface.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#include <Arduino.h>
#include <BMA400.h>
#include <Wire.h>

BMA400 bma400;
void setup()
{
// put your setup code here, to run once:
Serial.begin(115200);

Wire1.begin(GPIO_NUM_21, GPIO_NUM_22, 400000);

if (bma400.Initialize(Wire1)) // Using user defined (Wire1) interface & automatically resolving the address
{
printf("BMA400 Sensor successfully found\r\n");
bma400.Setup(
BMA400::power_mode_t::NORMAL,
BMA400::output_data_rate_t::Filter1_048x_200Hz,
BMA400::acceleation_range_t::RANGE_4G);
}
else
printf("Error! no BMA400 sensor found\r\n");
}

void loop()
{
// put your main code here, to run repeatedly:
float acceleration[3] = {0};
bma400.ReadAcceleration(acceleration);
printf("Acceleration(g) [X, Y, Z] = %2.2f %2.2f %2.2f\r\n", acceleration[0], acceleration[1], acceleration[2]);
delay(1000);
}
2 changes: 1 addition & 1 deletion src/BMA400.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ void BMA400::ReadAcceleration(int16_t *values)
}

/*!
* @brief Getting Acceleration - processed in mg
* @brief Getting Acceleration - processed in g
* @param values must be address of an array (float) with at least 3 elements
*/
void BMA400::ReadAcceleration(float *values)
Expand Down

0 comments on commit 9e74386

Please sign in to comment.