   for (int i = 0; i<= d; i++) {
     sum += history[i];
   }
-  Serial.print("\tsum: ");
-  Serial.print(sum);
   ave = sum / num_data;
   index++;
   if (index >= num_for_ave) {


void setup()
{
  Serial.begin(9600);
  accelero.begin(13, 12, 11, 10, A0, A1, A2);
  accelero.setARefVoltage(3.3);                   //sets the AREF voltage to 3.3V
  accelero.setSensitivity(LOW);                   //sets the sensitivity to +/-6G
  accelero.calibrate();
}

void loop()
{
  pre_x = x;
  x = accelero.getXRaw();
  checkWalking(x);
  y = accelero.getYRaw();
  z = accelero.getZRaw();
  Serial.print("\nx: ");
  Serial.print(x);
  Serial.print("\ty: ");
  Serial.print(y);
  Serial.print("\tz: ");
  Serial.print(z);
  Serial.print("\tcnt: ");
  Serial.print(cnt);
  Serial.print("\tnum_data: ");
  Serial.print(num_data);
  Serial.print("\tindex: ");
  Serial.print(index);
  Serial.print("\tave: ");
  Serial.print(ave);
  delay(100);                                     //(make it readable)
}

void checkWalking(int x) {

/* Copyright 2012 Google Inc.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
 * USA.
 *
 * Project home page: http://code.google.com/p/usb-serial-for-android/
 */

#define STATE_INIT 0
#define STATE_WRITE_FOR_CONNECT 1
#define STATE_WRITE_FOR_DISCONNECT 2
#define STATE_WRITE_DONE_FOR_CONNECT 3
#define STATE_WRITE_DONE_FOR_DISCONNECT 4
#define STATE_READ 5

#define STRING_EOS "#_EOS_"
#define COMMAND_START_TO_LOAD 0xFF

#include <AcceleroMMA7361.h>

static int state = STATE_INIT;

AcceleroMMA7361 accelero;
int x;
