 void loop()
 {
   batteryUpdate();
-  delay(3000);
+  delay(100);
 }
 
 void batteryDraw()

  Robot.line(127, 1, 127, 5);
}

void batteryUpdate()
{
  Robot.noStroke();
  value_old = value;
  value = readVcc();
  int level = map(value, 4400, 5000, 1, 11);
  if (level < 3) {
    Robot.fill(255,0,0); 
  } else if (level < 7) {
    Robot.fill(0,0,255); 
  } else {
    Robot.fill(0,255,0); 
  }

  delay(2); // Wait for Vref to settle
  ADCSRA |= _BV(ADSC); // Start conversion
  while (bit_is_set(ADCSRA,ADSC)); // measuring
   
  uint8_t low  = ADCL; // must read ADCL first - it then locks ADCH  
  uint8_t high = ADCH; // unlocks both
   
  long result = (high<<8) | low;
  
  // return registries to previous settings, just in case.
  ADMUX = original_admux;
  ADCSRA = original_adcsra;
  ADCSRB = original_adcsrb;
 
  result = 1125300L / result; // Calculate Vcc (in mV); 1125300 = 1.1*1023*1000
  return (int) result; // Vcc in millivolts
}
