this is my solution:
#include <M5Stack.h>
#include <U8g2lib.h>
uint8_t bat = M5.Power.getBatteryLevel();
U8G2_SH1107_64X128_1_4W_HW_SPI u8g2(U8G2_R1, /* cs=*/ 14, /* dc=*/ 27, /* reset=*/ 33);
void setup(void) {
M5.begin();
Wire.begin();
u8g2.begin();
Serial.begin(9600);
}
void loop(void) {
delay(500);
Batteria();
}
void Batteria() {//
u8g2.firstPage();
do {
if (M5.Power.isCharging()) {
// DEBUG Serial.println("Battery is charging");
u8g2.setFont(u8g2_font_battery19_tn);
u8g2.drawGlyph(2, 20, 48);
u8g2.setFont(u8g2_font_unifont_t_symbols);
u8g2.drawGlyph(1, 16, 8623); //fulmine
} else {
u8g2.setFont(u8g2_font_battery19_tn);
u8g2.drawGlyph(2, 20, 48); // VUOTA
if (bat > 50) {
u8g2.drawGlyph(2, 20, 49); // una tacca
}
if (bat > 100) {
u8g2.drawGlyph(2, 20, 50); // //due tacche
}
if (bat > 150) {
u8g2.drawGlyph(2, 20, 51); // tre tacche
}
if (bat > 200) {
u8g2.drawGlyph(2, 20, 52); // quattro tacche
}
if (bat > 250) {
u8g2.drawGlyph(2, 20, 53); // cinque tacche
}
}
/// FOR DEBUG/////
//u8g2.setFont(u8g2_font_7Segments_26x42_mn);
//u8g2.setCursor(20, 52);
//u8g2.print(bat);
//Serial.print(bat);
//Serial.println(" %");
} while ( u8g2.nextPage() );
}
right now.....