Skip to content

Commit

Permalink
PowerC
Browse files Browse the repository at this point in the history
  • Loading branch information
Tinyu-Zhao committed Mar 12, 2022
1 parent 3486eec commit ebdd51d
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
47 changes: 47 additions & 0 deletions examples/Hat/PowerC_IP5209/PowerC_IP5209.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@

// Download the required library functions https://github.com/m5stack/M5_IP5209
#include <M5StickCPlus.h>
#include <Wire.h>

#include "M5_IP5209.h"
TFT_eSprite canvas = TFT_eSprite(&M5.Lcd);

M5_IP5209 powerc;

void setup() {
M5.begin();
M5.Lcd.setRotation(1);
canvas.createSprite(160, 80);
canvas.setTextColor(ORANGE);
while (!powerc.begin()) {
canvas.fillSprite(BLACK);
canvas.setCursor(0, 10);
canvas.println("POWERC INIT ERROR");
canvas.println("Pls click the power btn and check the I2C connect.");
canvas.pushSprite(10, 0);
delay(1000);
}
}

char info[50];

void loop() {
if (powerc.update()) {
float v = powerc.voltage;
float i = powerc.current;
float p = powerc.power;
bool charge = powerc.charged;
canvas.fillSprite(BLACK);
canvas.setCursor(0, 10);
sprintf(info, "BAT: %1.2fV\r\n%1.2fmA\r\npower:%1.2fw\r\nischarge: %d",
v, i, p, charge);
canvas.println(info);
canvas.pushSprite(10, 0);
delay(100);
} else {
canvas.fillSprite(BLACK);
canvas.setCursor(0, 10);
canvas.println("powerc update error..");
canvas.pushSprite(10, 0);
}
}
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ category=Device Control
url=https://github.com/m5stack/M5StickC-Plus.git
architectures=esp32
includes=M5StickCPlus.h
depends=M5_EzData,ArduinoJson,PubSubClient,HX711 Arduino Library,M5_RoverC,UNIT_UHF_RFID,M5_JoyC,ATOM_DTU_CAT1
depends=M5_EzData,ArduinoJson,PubSubClient,HX711 Arduino Library,M5_RoverC,UNIT_UHF_RFID,M5_JoyC,ATOM_DTU_CAT1,M5_IP5209

0 comments on commit ebdd51d

Please sign in to comment.