
Arduino入門
StickC-Plus SE のバッテリー状態を取得するための API とサンプルプログラムです。
#include "M5Unified.h"
void setup()
{
M5.begin();
Serial.begin(115200);
M5.Lcd.setTextDatum(middle_center);
M5.Lcd.setTextFont(&fonts::FreeMonoBold9pt7b);
M5.Lcd.setTextSize(1);
M5.Lcd.setRotation(1);
}
void loop()
{
M5.Lcd.clear();
bool isCharging = M5.Power.isCharging();
int vol_per = M5.Power.getBatteryLevel();
int vol = M5.Power.getBatteryVoltage();
M5.Lcd.setCursor(0, 30);
M5.Lcd.printf("Charging: %s \n\n", isCharging ? "Yes" : "No");
M5.Lcd.setCursor(0, 60);
M5.Lcd.printf("Bat_level: %d%%", vol_per);
M5.Lcd.setCursor(0, 90);
M5.Lcd.printf("Bat_voltage: %d%mV", vol);
delay(2000);
} このプログラムは、充電状態、バッテリー残量、バッテリー電圧を画面に表示し、2 秒ごとに更新します。
StickC-Plus SE の電源機能には、M5Unified ライブラリの Power_Class を使用しています。その他の API については、以下のドキュメントを参照してください。