/* Measures the supply voltage by averaging multiple readings.  */
static float measureSupplyVoltage(unsigned int avg)
/* Measures the supply voltage by averaging multiple readings.  */
static float measureSupplyVoltage(unsigned int avg)
{
   uint16_t adcData;
   float supplyVoltage;
   int i;
   adcInit();
   supplyVoltage = 0;
   for( i = 0; i < avg; i++ ) {
      adcData = getAdcSample();
      supplyVoltage += (float) adcData * 5.0 / 4095.0;
   }
   adcDeInit();
   supplyVoltage = supplyVoltage / (float) avg;
   return supplyVoltage;
}