// =============================== Init ======================================== static inline void ShowChargeLevel() { Adc_t Adc; uint32_t rslt = 0; Adc.Init(); for(uint8_t i=0; i<8; i++) { Adc.StartConversion(); while(!Adc.ConversionCompleted()) chThdSleepMilliseconds(20); rslt += Adc.Result(); } Adc.Disable(); Adc.ClockOff(); rslt >>= 3; rslt = (rslt * 16225) / 10000; Uart.Printf("mv=%u\r", rslt); // Show charge BlueLed.On(LED_LOW); // Always if(rslt > 3700) RedLed.On (LED_LOW); if(rslt > 3800) YellowLed.On(LED_LOW); if(rslt > 3900) GreenLed.On (LED_LOW); if(rslt > 4050) WhiteLed.On (LED_LOW); }