using more than one accelerometers(MMA8451)

Hi, I am a total beginner with arduino
I am working on a project that need 2 accelerometers.
The accelerometers that I am using is MMA8451 from Adafruit that uses i2c.
I managed to change the i2c address of one of them,
but I have no idea on what I am supposed to do to use these two different addresses and get readings from each accelerometer separately.
The demo sketches for reading the values from the accelerometer seems to read the values from only one accelerometer.
I know I need to create a new sketch in order to read the values from the 2 accelerometers separate,
but since I am really new to arduino I cannot figure it out by myself.
Below is the demo sketch that I downloaded from Adafruit's website.
Please help me out on this!

/**************************************************************************/
/*!
@file Adafruit_MMA8451.h
@author K. Townsend (Adafruit Industries)
@license BSD (see license.txt)

This is an example for the Adafruit MMA8451 Accel breakout board
----> Adafruit Triple-Axis Accelerometer - ±2/4/8g @ 14-bit - MMA8451 : ID 2019 : $7.95 : Adafruit Industries, Unique & fun DIY electronics and kits

Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!

@section HISTORY

v1.0 - First release
*/
/**************************************************************************/

#include <Wire.h>
#include <Adafruit_MMA8451.h>
#include <Adafruit_Sensor.h>

Adafruit_MMA8451 mma = Adafruit_MMA8451();

void setup(void) {
Serial.begin(9600);

Serial.println("Adafruit MMA8451 test!");

if (! mma.begin()) {
Serial.println("Couldnt start");
while (1);
}
Serial.println("MMA8451 found!");

mma.setRange(MMA8451_RANGE_2_G);

Serial.print("Range = "); Serial.print(2 << mma.getRange());
Serial.println("G");

}

void loop() {
// Read the 'raw' data in 14-bit counts
mma.read();
Serial.print("X:\t"); Serial.print(mma.x);
Serial.print("\tY:\t"); Serial.print(mma.y);
Serial.print("\tZ:\t"); Serial.print(mma.z);
Serial.println();

/* Get a new sensor event */
sensors_event_t event;
mma.getEvent(&event);

/* Display the results (acceleration is measured in m/s^2) */
Serial.print("X: \t"); Serial.print(event.acceleration.x); Serial.print("\t");
Serial.print("Y: \t"); Serial.print(event.acceleration.y); Serial.print("\t");
Serial.print("Z: \t"); Serial.print(event.acceleration.z); Serial.print("\t");
Serial.println("m/s^2 ");

Serial.println();
delay(1000);

}

dongjune1:
Hi, I am a total beginner with arduino
I am working on a project that need 2 accelerometers.
The accelerometers that I am using is MMA8451 from Adafruit that uses i2c.
I managed to change the i2c address of one of them,
but I have no idea on what I am supposed to do to use these two different addresses and get readings from each accelerometer separately.
The demo sketches for reading the values from the accelerometer seems to read the values from only one accelerometer.
I know I need to create a new sketch in order to read the values from the 2 accelerometers separate,
but since I am really new to arduino I cannot figure it out by myself.
Below is the demo sketch that I downloaded from Adafruit's website.
Please help me out on this!

If you are going to use AdaFruit's library, you will have to edit the library to allow you to specify the I2C address of the Sensor. There are two possible addressed, 0x1C and 0x1D. I am not familiar with the Adafruit library, but I would look in the begin() function and find were the I2C address is hard coded, change the begin() function to accept a byte parameter, pass it your I2C address.
Your new begin() function would store this address in a class private variable. inside the library, every function would have to be modified to use this private variable instead of the hardcoded value.

Adafruit_MMA8451 mma = Adafruit_MMA8451();

Adafruit_MMA8451 mma2 = Adafruit_MMA8451();

void setup(){
 if(!mma.begin(0x1C)) { bla bla ..}

 if(!mma2.begin(0x1D)){ bla bla ..}

}

Chuck.