Sensing change of direction of repeating movement (MMA8452Q sensor)

groundFungus:
Are you comparing the last value(S) read by the accelerometer to the newest reading to look for a change ala the state change detection method? That is for a button but the idea is the same.

Post your code and we can better help. Read the how to use this forum-please read sticky to see how to post code.

This my code. It is based on the starting example of the sensor and it doesn't contain code yet for automatic "peek" detection because the acceleration differences during direction change seem very little...

/******************************************************************************
MMA8452Q_Basic.ino
SFE_MMA8452Q Library Basic Example Sketch
https://github.com/sparkfun/MMA8452_Accelerometer

This sketch uses the SFE_MMA8452Q library to initialize the
accelerometer, and stream values from it.

Hardware hookup:
  Arduino --------------- MMA8452Q Breakout
    3.3V  ---------------     3.3V
    GND   ---------------     GND
  SDA (A4) --\/330 Ohm\/--    SDA
  SCL (A5) --\/330 Ohm\/--    SCL

The MMA8452Q is a 3.3V max sensor, so you'll need to do some 
level-shifting between the Arduino and the breakout. Series
resistors on the SDA and SCL lines should do the trick.

Development environment specifics:
  IDE: Arduino 1.0.5
  Hardware Platform: Arduino Uno
******************************************************************************/

#include <Wire.h> // Must include Wire library for I2C
#include <SFE_MMA8452Q.h> // Includes the SFE_MMA8452Q library

MMA8452Q accel;

void setup()
{
  Serial.begin(9600);
  Serial.println("MMA8452Q Test!");
  

  //     Initialize with FULL-SCALE and DATA RATE setting. Control how fast the accelerometer produces
  //     data by using one of the following options in the second param:
  //     ODR_800, ODR_400, ODR_200, ODR_100, ODR_50, ODR_12,
  //     ODR_6, or ODR_1. 
  //     Sets to 800, 400, 200, 100, 50, 12.5, 6.25, or 1.56 Hz. See http://www.jneurosci.org/content/19/20/9073 for G-forces during speech
  accel.init(SCALE_4G, ODR_12);
}

void loop()
{
  if (accel.available())
  {
    accel.read();
    printCalculatedAccels();    
    Serial.println(); // Print new line every time.
  }
}

void printCalculatedAccels()
{ 
  Serial.print(accel.cx, 3);
  Serial.print("\t");
  Serial.print(accel.cy, 3);
  Serial.print("\t");
  Serial.print(accel.cz, 3);
  Serial.print("\t");
  
  float Xsquare = 0, Ysquare = 0, Zsquare = 0, XYZsum = 0, RootXYZ = 0;
  Xsquare = pow(accel.cx, 2);
  Ysquare = pow(accel.cy, 2);
  Zsquare = pow(accel.cz, 2);
  XYZsum = Xsquare + Ysquare + Zsquare;
  RootXYZ = sqrt(XYZsum);
  Serial.print(RootXYZ, 3);
  Serial.print("\t");
}