     back = backBentBack();
   }
 
+  if (counter < 9){
+    counter++;
+  } else {
+    counter = 0;
+  }
+
+  Serial.print(rightArm);
+
   //add new data to the arrays
   prevBackData[counter] = back;
   prevLeftData[counter] = leftArm;
   prevRightData[counter] = rightArm;
 
-  if (counter < 10){
-    counter++;
-  } else {
-    counter = 0;
-  }
+  prevBackCount = 0;
+  prevLeftCount = 0;
+  prevRightCount = 0;
 
   //collect # right
-  for (int i = 0; i < 10; i++){
-    if (prevBackData[i]){
+  for (int i = 0; i < 9; i++){
+    if (prevBackData[i] == true){
       prevBackCount++;
     }
-    if (prevLeftData[i]){
+    if (prevLeftData[i] == true){
       prevLeftCount++;
     }
-    if (prevRightData[i]){
+    if (prevRightData[i] == true){
       prevRightCount++;
     }
   }

  } else {
    rightArm = false;
  }



  //build JSON string
  jsonString = "{\"type\":\"";
  jsonString += type;
  jsonString += "\",\"name\":\"";
  jsonString += name;
  jsonString += "\",\"leftArm\":\"";
  
  jsonString += leftArm;
  jsonString += "\",\"rightArm\":\"";
  jsonString += rightArm;
  jsonString += "\",\"back\":\"";
  jsonString += back;
  jsonString += "\"}";

  //Print JSON to Serial if different
  if (oldJSON != jsonString){
    Serial.println(jsonString);
    oldJSON = jsonString;
  }
}

//Buffer for json parsing
//Could potentially take up too much memory
DynamicJsonBuffer jsonBuffer;
boolean updated = false;

//For smoothing of data
boolean prevBackData[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
boolean prevLeftData[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
boolean prevRightData[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};

int counter = 0;

