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
@@ -43,14 +49,25 @@ void setup() {
43
49
canvas.setFont (&FreeSans12pt7b);
44
50
canvas.setTextColor (ST77XX_WHITE);
45
51
46
- if (!lc.begin ()) {
47
- Serial.println (F (" Couldnt find Adafruit LC709203F?\n Make sure a battery is plugged in!" ));
48
- while (1 );
52
+ if (lc_bat.begin ()) {
53
+ Serial.println (" Found LC709203F" );
54
+ Serial.print (" Version: 0x" ); Serial.println (lc_bat.getICversion (), HEX);
55
+ lc_bat.setPackSize (LC709203F_APA_500MAH);
56
+ lcfound = true ;
49
57
}
58
+ else {
59
+ Serial.println (F (" Couldnt find Adafruit LC709203F?\n Checking for Adafruit MAX1704X.." ));
60
+ delay (200 );
61
+ if (!max_bat.begin ()) {
62
+ Serial.println (F (" Couldnt find Adafruit MAX1704X?\n Make sure a battery is plugged in!" ));
63
+ while (1 ) delay (10 );
64
+ }
65
+ Serial.print (F (" Found MAX17048" ));
66
+ Serial.print (F (" with Chip ID: 0x" ));
67
+ Serial.println (max_bat.getChipID (), HEX);
68
+ maxfound = true ;
50
69
51
- Serial.println (" Found LC709203F" );
52
- Serial.print (" Version: 0x" ); Serial.println (lc.getICversion (), HEX);
53
- lc.setPackSize (LC709203F_APA_500MAH);
70
+ }
54
71
55
72
if (TB.scanI2CBus (0x77 )) {
56
73
Serial.println (" BME280 address" );
@@ -73,11 +90,11 @@ void setup() {
73
90
uint8_t j = 0 ;
74
91
75
92
void loop () {
76
- Serial.println (" **********************" );
77
-
78
- TB.printI2CBusScan ();
79
93
80
94
if (j % 5 == 0 ) {
95
+ Serial.println (" **********************" );
96
+
97
+ TB.printI2CBusScan ();
81
98
canvas.fillScreen (ST77XX_BLACK);
82
99
canvas.setCursor (0 , 25 );
83
100
canvas.setTextColor (ST77XX_RED);
@@ -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);
@@ -107,6 +132,5 @@ void loop() {
107
132
}
108
133
109
134
TB.setColor (TB.Wheel (j++));
110
- delay (10 );
111
135
return ;
112
136
}
0 commit comments