English
English
简体中文
日本語
pdf-icon

Arduino Quick Start

2. Devices & Examples

5. Extensions

6. Applications

StackChan Battery

StackChan battery status reading example program.

Example Program

Compilation Requirements

  • M5Stack Board Manager Version >= 3.3.7
  • Development Board Selection = M5CoreS3
  • M5StackChan Library Version >= 1.0.0
cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
#include <M5StackChan.h>

void setup() {
    M5StackChan.begin();
    M5StackChan.Display().setFont(&fonts::FreeMonoBold12pt7b);

    M5StackChan.Display().clear();
    M5StackChan.Display().setCursor(0, 0);
    M5StackChan.Display().print("StackChan Battery");
}

void loop() {
    M5StackChan.update();
    float voltage = M5StackChan.getBatteryVoltage();
    float current = M5StackChan.getBatteryCurrent() * 1000;

    M5StackChan.Display().setCursor(0, 50);
    M5StackChan.Display().printf("Voltage: %0.2fV", voltage);

    M5StackChan.Display().setCursor(0, 100);
    M5StackChan.Display().printf("Current: %0.2fmA", current);

    delay(1000);
}

This program will display battery voltage and current information on the screen, refreshing every second.

On This Page