Skip to content

Commit 38ba8a0

Browse files
committed
Arduino IDE Sketch added for BasicDemo
1 parent b3ef026 commit 38ba8a0

File tree

3 files changed

+88
-4
lines changed

3 files changed

+88
-4
lines changed

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ Need Help? [![Discord](https://img.shields.io/badge/Discuss-on%20Discord-7289d9?
44

55
# Initial Development!
66
Please be aware that this Library is currently in its initial development stages. It will function on the ESP32 just fine (tested and verified using PlatformIO for /examples/BasicDemo).
7-
The next release will include a .ino Sketch for hte BasicDemo in the Arduino IDE.
8-
Immediately thereafter, working support for the Arduino Uno and Nano R3 will be completed, tested, and submitted for 0.0.4.
7+
The next release will include working support for the Arduino Uno and Nano R3 will be completed, tested, and submitted for 0.0.4.
98

109
# LithiumPowered
1110
A (hopefully) Universal Library for Lithium-Powered Projects, designed to be available for both Arduino IDE and PlatformIO Projects.
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
#include <Arduino.h>
2+
3+
#ifdef ESP32
4+
#include <Preferences.h> // CRITICAL FOR ESP32 DEVICES!
5+
#endif
6+
7+
#include <LithiumPowered.hpp>
8+
9+
#define BATTERY_RATED_CAPACITY 900.00 // Set this to the Rated Capacity of your Battery in mAh!
10+
11+
class MyBatteryCallbacks: public BatteryCallbacks {
12+
public:
13+
virtual void onBatteryNowCharging() {
14+
Serial.println("Battery is now Charging!");
15+
};
16+
17+
virtual void onBatteryNowDischarging() {
18+
Serial.println("Battery is no longer Charging!");
19+
};
20+
21+
virtual void onBatteryRemainingCapacityChanged() {
22+
Serial.print("Battery Update: ");
23+
Serial.print(Battery.getPercentage());
24+
Serial.print("% ");
25+
Serial.print(Battery.getCurrentCapacity());
26+
Serial.print("mAh remaining. ");
27+
Serial.print(Battery.getIsCharging() ? "Charging at +" : "Discharging at ");
28+
Serial.print(Battery.getChangeCapacityWithPolarity());
29+
Serial.print("mAh");
30+
if (Battery.getIsCharging()) {
31+
Serial.print(" - Time to full: ");
32+
Serial.print(Battery.getTimeToChargeInMinutes());
33+
}
34+
else {
35+
Serial.print(" - Time to empty: ");
36+
Serial.print(Battery.getTimeToDischargeInMinutes());
37+
}
38+
Serial.println(" min");
39+
};
40+
41+
virtual void onBatteryRecalibrated() {
42+
Serial.print("Maximum Battery Capacity has been Recalibrated!");
43+
};
44+
};
45+
46+
//#define USE_CUSTOM_GPIO // Uncomment this line if you need to use Custom GPIO Pins!
47+
48+
#ifdef USE_CUSTOM_GPIO
49+
class MyBatteryGPIO: public BatteryGPIO {
50+
public:
51+
// Override this to provide the GPIO Pin Number for the Coloumb Counter's Polarity Pin
52+
virtual uint8_t getPinPolarity() {
53+
return 4;
54+
}
55+
56+
// Override this to provide the GPIO Pin Number for the Coloumb Counter's Interrupt Pin
57+
virtual uint8_t getPinInterrupt() {
58+
return 35;
59+
}
60+
61+
// Override this to provide the GPIO Pin Number for the Coloumb Counter's High State Reference Pin
62+
virtual uint8_t getPinRefHigh() {
63+
return 23;
64+
}
65+
66+
// Override this to provide the GPIO Pin Number for the Coloumb Counter's Low State Reference Pin
67+
virtual uint8_t getPinRefLow() {
68+
return 5;
69+
}
70+
};
71+
#endif
72+
73+
void setup() {
74+
Serial.begin(115200); // Initialise Serial interface at 115200 Baud
75+
76+
#ifdef USE_CUSTOM_GPIO
77+
Battery.setGpio(new MyBatteryGPIO()); // We want to use specific GPIO Pins
78+
#endif
79+
Battery.setCallbacks(new MyBatteryCallbacks()); // Use our custom Callbacks for Battery Events
80+
Battery.setup(BATTERY_RATED_CAPACITY); // Initialise the LithiumPowered Battery System
81+
}
82+
83+
void loop() {
84+
Battery.loop(); // Required to perform State Updates for the LithiumPowered Battery System.
85+
}

library.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
name=Lithium-Powered
2-
version=0.0.2
1+
name=LithiumPowered
2+
version=0.0.3
33
author=Flowduino
44
maintainer=Flowduino <support@flowduino.com>
55
sentence=All-In-One Code Solution for Lithium Battery Management using the LTC4150 Coulomb Counter circuit.

0 commit comments

Comments
 (0)