An M5Stack library for displaying battery charge.
- Display battery charge
- Customize size and rotation
- Initialize your Platform IO project
- Install the library and its dependency
platformio init -d . -b m5stack-core-esp32
platformio lib install M5Battery
platformio lib install M5Unified
Warning This library has been tested only with M5Stack and M5StickC-PLUS.
#include <M5Unified.h>
#include <M5Battery.h>
M5Battery bat;
void setup() {
auto cfg = M5.config();
M5.begin(cfg);
bat.init(0, 0);
}
void loop() {
M5.update();
if (M5.BtnA.wasPressed()) {
if (bat.isDrawing()) {
bat.hide();
}
else {
bat.show();
}
}
if (M5.BtnB.wasPressed()) {
bat.setPosition(random(0, M5.Display.width()), random(0, M5.Display.height()));
bat.setRotation(random(0, 3));
bat.setSize(random(1, 7));
}
delay(100);
}
You can also read the module doc for a list of supported calls.
Yushin Ito
MIT License