3
3
// SPDX-License-Identifier: MIT
4
4
5
5
#include < Arduino.h>
6
+ #include " Adafruit_MAX1704X.h"
6
7
#include " Adafruit_LC709203F.h"
7
8
#include < Adafruit_NeoPixel.h>
8
9
#include " Adafruit_TestBed.h"
@@ -14,14 +15,19 @@ Adafruit_BME280 bme; // I2C
14
15
bool bmefound = false ;
15
16
extern Adafruit_TestBed TB;
16
17
17
- Adafruit_LC709203F lc;
18
+ Adafruit_LC709203F lc_bat;
19
+ Adafruit_MAX17048 max_bat;
20
+
18
21
Adafruit_ST7789 display = Adafruit_ST7789(TFT_CS, TFT_DC, TFT_RST);
19
22
20
23
GFXcanvas16 canvas (240 , 135 );
21
24
25
+ bool maxfound = false ;
26
+ bool lcfound = false ;
27
+
22
28
void setup () {
23
29
Serial.begin (115200 );
24
- // while (! Serial) delay(10);
30
+ // while (! Serial) delay(10);
25
31
26
32
delay (100 );
27
33
@@ -42,15 +48,26 @@ void setup() {
42
48
display.setRotation (3 );
43
49
canvas.setFont (&FreeSans12pt7b);
44
50
canvas.setTextColor (ST77XX_WHITE);
45
-
46
- if (!lc.begin ()) {
47
- Serial.println (F (" Couldnt find Adafruit LC709203F?\n Make sure a battery is plugged in!" ));
48
- while (1 );
51
+ if (lc_bat.begin ()) {
52
+ Serial.println (" Found LC709203F" );
53
+ Serial.print (" Version: 0x" ); Serial.println (lc_bat.getICversion (), HEX);
54
+ lc_bat.setPackSize (LC709203F_APA_500MAH);
55
+ lcfound = true ;
49
56
}
57
+ else {
58
+ Serial.println (F (" Couldnt find Adafruit LC709203F?\n Checking for Adafruit MAX1704X.." ));
59
+ delay (200 );
60
+ if (!max_bat.begin ()) {
61
+ Serial.println (F (" Couldnt find Adafruit MAX1704X?\n Make sure a battery is plugged in!" ));
62
+ while (1 ) delay (10 );
63
+ }
64
+ Serial.print (F (" Found MAX17048" ));
65
+ Serial.print (F (" with Chip ID: 0x" ));
66
+ Serial.println (max_bat.getChipID (), HEX);
67
+ maxfound = true ;
50
68
51
- Serial.println (" Found LC709203F" );
52
- Serial.print (" Version: 0x" ); Serial.println (lc.getICversion (), HEX);
53
- lc.setPackSize (LC709203F_APA_500MAH);
69
+ }
70
+
54
71
55
72
if (TB.scanI2CBus (0x77 )) {
56
73
Serial.println (" BME280 address" );
@@ -87,10 +104,18 @@ void loop() {
87
104
canvas.setTextColor (ST77XX_GREEN);
88
105
canvas.print (" Battery: " );
89
106
canvas.setTextColor (ST77XX_WHITE);
90
- canvas.print (lc.cellVoltage (), 1 );
91
- canvas.print (" V / " );
92
- canvas.print (lc.cellPercent (), 0 );
93
- canvas.println (" %" );
107
+ if (lcfound == true ) {
108
+ canvas.print (lc_bat.cellVoltage (), 1 );
109
+ canvas.print (" V / " );
110
+ canvas.print (lc_bat.cellPercent (), 0 );
111
+ canvas.println (" %" );
112
+ }
113
+ else {
114
+ canvas.print (max_bat.cellVoltage (), 1 );
115
+ canvas.print (" V / " );
116
+ canvas.print (max_bat.cellPercent (), 0 );
117
+ canvas.println (" %" );
118
+ }
94
119
canvas.setTextColor (ST77XX_BLUE);
95
120
canvas.print (" I2C: " );
96
121
canvas.setTextColor (ST77XX_WHITE);
@@ -109,4 +134,4 @@ void loop() {
109
134
TB.setColor (TB.Wheel (j++));
110
135
delay (10 );
111
136
return ;
112
- }
137
+ }
0 commit comments