1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
|
int8_t batteryPercentage;
../..
if (!isADCReady)
{
//adcValue = analogRead(A0); //<============
adcValue = 950; // <=== test
//batteryVoltage = adcValue * 0.00410; // 4.2v / 1023 = 0.00410
batteryPercentage = (int8_t)((adcValue - 740) / 2.83); // 1023 - 740 = 283 pour 0 - 100% soit 3.3v à 2,4v
constexpr int seuilTensionBruteBasse = 930 ; // 3.0V ==> calculé par (3.0V * 1023) / 3.3V
//int tensionBrute =analogRead(A0);
int tensionBrute =adcValue; // <==== test
if (tensionBrute <= seuilTensionBruteBasse)
{
D_timestamp();
D_println("Batterie faible. Sommeil profond.");
D_printf("Battery Percentage: %i", batteryPercentage);
ESP.deepSleep(0);
}
D_timestamp();
D_println("ADC Reading ready");
D_timestamp();
D_printf("Battery Percentage: %i", batteryPercentage);
D_println();
bat =int8_t(&batteryPercentage);
updateBattery() ;
delay(1000);
//isADCReady = true;
}
**/**
void updateBattery()
{
int16_t tbx, tPar;
uint16_t tbw, tbh;
display.setRotation(3);
//display.mirror(false);
uint16_t x = 32;
uint16_t y = 24;
display.getTextBounds(bat, x, y, &tbx, &tPar, &tbw, &tbh); //<================
display.setFont(&FreeMonoBold9pt7b);
display.setTextColor(GxEPD_BLACK);
display.setPartialWindow(tbx, tPar, tbw, tbh);
//display.firstPage();
do {
display.fillScreen(GxEPD_WHITE);
display.setCursor(x, y);
display.print(bat); // <==================
} while (display.nextPage());
} |
Partager