#define N 5
float vetor[N];

float matriz[] = {1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
int comprimento = 0;

float MovAVG(float valor);

void setup() {
  // put your setup code here, to run once:
Serial.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly:
  if(comprimento < sizeof(matriz)){
    int x = matriz[comprimento++];
    float avg = MovAVG(x);
    //
    //
    Serial.print(x);
    Serial.write(9);
    Serial.print(avg);
    //Serial.write(9);
    //Serial.print(fpb);
    //Serial.write(9);    
    //Serial.print(kf);
    delay(100);
  }
}

float MovAVG(float valor){
  static boolean isFirstRunAVG = true;
  float avg;
  if(isFirstRunAVG){
    for(byte i=0;i<N;i++){
      vetor[i]=valor;
    }
    isFirstRunAVG = false;
  }
  avg = 0;
  for(byte i=0;i<N;i++){
    vetor[i]=vetor[i+1];
    avg += vetor[i];
  }
  vetor[N-1]=valor;
  avg += valor;
  avg/=N;
  return(avg);
}