3-Axis Accelerometer MMA7455 Tilt Sensor Help

Hey Guys,

So I’m a bit new to sensors and I’m doing a school project on this MMA7455 tilt sensor that I have recently set up from the following site: https://arduino-info.wikispaces.com/accelerometer-MMA7455?responseToken=018173f92ea03de7e0011a7d7c983677

However, the teacher needs something unique rather than a simple code to make it just work. If they’re any suggestions on what I can do with the sensor, that will be much appreciated.

I have an idea of when the tilt occurs either forward or backwards or left or right there can be a led lighting up followed by a beep (different frequency of beeps from a piezo speaker); however, i need help setting up the code for this. If anyone can help or any other ideas that will be nice.

Here is the code so far that i used to calibrate the sensor with:

/*-----( Import needed libraries )-----*/
#include <Wire.h> //Include the Wire library
#include <MMA_7455.h> //Include the MMA_7455 library

/*-----( Declare Constants and Pin Numbers )-----*/

/*-----( Declare objects )-----*/
MMA_7455 mySensor = MMA_7455(); //Make an instance of MMA_7455

/*-----( Declare Variables )-----*/
char xVal, yVal, zVal; //Variables for the values from the sensor

void setup()   /****** SETUP: RUNS ONCE ******/
{
 Serial.begin(9600);
 delay(500);
 Serial.println("MMA7455 Accelerometer Test. terry@yourduino.com");
 // Set the sensitivity you want to use
 // 2 = 2g, 4 = 4g, 8 = 8g
 mySensor.initSensitivity(2); // Good for "Tilt" measurements
/* Calibrate the Offset. Calibrate, in Flat position, try to
   get: xVal = 0, yVal = 0, zVal = +63 (1 G)
  !!!Activate this after having the first values read out!!!
  Suggestion: Run this with offsets = 0,0,0 and see needed correction
*/
 // mySensor.calibrateOffset(0,0,0); //Uncomment for first try: find offsets
 // mySensor.calibrateOffset(-5.0, 13.0, -12.0); //Then Uncomment and use this
 
}//--(end setup )---

void loop()   /****** LOOP: RUNS CONSTANTLY ******/
{
 xVal = mySensor.readAxis('x'); //Read out the 'x' Axis
 yVal = mySensor.readAxis('y'); //Read out the 'y' Axis
 zVal = mySensor.readAxis('z'); //Read out the 'z' Axis
 Serial.print("X = ");
 Serial.print(xVal, DEC);
 Serial.print("   Y = ");
 Serial.print(yVal, DEC);
 Serial.print("   Z = ");
 Serial.println(zVal, DEC);
 delay(1000);
/*--( Show tilt [Assumes unit has been calibrated ] )----*/  
 if (xVal < -20) Serial.println("Tilted LEFT");
 if (xVal >  20) Serial.println("Tilted RIGHT");  
 if (yVal < -20) Serial.println("Tilted TOWARDS");  
 if (yVal >  20 ) Serial.println("Tilted AWAY");   
 if (zVal < -45 ) Serial.println("UPSIDE DOWN!");    
}//--(end main loop )---

/*-----( Declare User-written Functions )-----*/


//*********( THE END )***********

Thank You.

Please read and follow the directions in the "How to use this forum" post, and edit your post to add code tags.

Alright I did, you got any suggestions now so you can see my code better.