 NewPing sonar4(Ping4, Ping4, 200);
 
 //global variables
-int boxcar[MovingAverageWidth];
-int boxcar_index = 0;
+int boxcar[MovingAverageWidth*NoAverageDataSets];
+int boxcar_index[NoAverageDataSets];
 
 void setup() {
   

}    


void boxcar_addValue(int add){
    
    if(boxcar_index == MovingAverageWidth){
        boxcar_index = 0;
        boxcar[boxcar_index] = add/MovingAverageWidth;
    } else{
        boxcar_index++;
        boxcar[boxcar_index] = add/MovingAverageWidth;
    }
    
}
        

int boxcar_getAverage() {
    int mean = 0;
    for (int i =0; i < MovingAverageWidth; i++){
        mean = mean + boxcar[i];       
    }    
    return mean;
}

#define Dark            400

//other deffinitions
#define BrightnessTop      0
#define MovingAverageWidth 5
#define NoAverageDataSets  3


//app control deffinition
