     }
   }
 
+  if (time.elapsed (100)) {
+    // subtract the last reading:
+    total= total - readings[index];         
+    // read from the sensor:  
+    readings[index] = iout.read();
+    delay(1); 
+    // add the reading to the total:
+    total= total + readings[index];       
+    // advance to the next position in the array:  
+    index = index + 1;                    
+
+    // if we're at the end of the array...
+    if (index >= numReadings)              
+      // ...wrap around to the beginning: 
+      index = 0;                           
+
+    // calculate the average:
+    average = total / numReadings;
+  }        
+
   // send voltage and current
   if (time.elapsed(1000)) {
     vout.send(vout.read());
-    iout.send(iout.read());
+    iout.send(average);
     Serial.print("time:");
     Serial.println(millis());
   }

// array[0] will be the number of arguments in the command
int array[MAX_ARGS];


void setup(){


  motors.reset();
  
  time.reset();

// initialize all the readings to 0: 
  for (int thisReading = 0; thisReading < numReadings; thisReading++)
    readings[thisReading] = 0;     
}

void loop(){
