-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3486eec
commit ebdd51d
Showing
2 changed files
with
48 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters