   
   bool batState = false;
 
-  checkVoltage(batState);
+  float value = checkVoltage(batState);
+  if(batState)
+    push(value);
 
   if(batState)
   {

    delay(50);
  }

  average = 0.0f;
  for(int i=0; i < N_Voltage; ++i)
    average += values[i];
  average /= (float) N_Voltage;
  
  hasVoltage = average > minvoltage;
}

void changeChargerState(bool on)

const uint8_t pinVoltage = A0;

const uint8_t N_Voltage = 10;
const uint8_t N_RecentAverages = 5;

const char NoBat[] = "No BAT!";
const char BatOk[] = "BAT ok!";
const char Unknown[] = "???";
const char Initialize[] = "Initialize...";
const char Ready[] = "Ready";

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

float minvoltage = 35.f;
float recentaverages[N_RecentAverages] = {0.0f};

void push(float average)
{
  for(uint8_t i=0; i < N_RecentAverages - 1; ++i)
    recentaverages[i] = recentaverages[i];
  recentaverages[N_RecentAverages - 1] = average;
}

inline float last()
{
  return recentaverages[N_RecentAverages - 1];
}

void setup() 
{
