@@ -39,34 +39,44 @@ Board board;
39
39
Charger charger;
40
40
MAX1726Driver fuelgauge (&Wire1);
41
41
42
+ void blinkLed (int ledPin, int delayTime = 1000 ){
43
+ digitalWrite (ledPin, LOW);
44
+ delay (delayTime);
45
+ digitalWrite (ledPin, HIGH);
46
+ delay (delayTime);
47
+ }
48
+
42
49
void setup () {
43
50
// When uploading this sketch to the M4 core, it just goes to standby mode.
44
51
#if defined(ARDUINO_GENERIC_STM32H747_M4)
45
52
board.standByUntilWakeupEvent ();
46
53
return ;
47
54
#endif
48
-
49
- charger.begin ();
50
55
51
- // Turn off the built-in LED
56
+ pinMode (LEDR, OUTPUT); // Used to indicate errors
57
+ digitalWrite (LEDR, HIGH); // Turn off the red LED
52
58
pinMode (LED_BUILTIN, OUTPUT);
53
- digitalWrite (LED_BUILTIN, HIGH);
59
+ digitalWrite (LED_BUILTIN, HIGH); // Turn off the built-in LED
60
+ pinMode (LEDB, OUTPUT); // Used to indicate that the board is awake
54
61
55
62
// Turn on the blue LED to show that the board is still awake
56
- pinMode (LEDB, OUTPUT);
57
63
digitalWrite (LEDB, LOW);
58
64
65
+ if (!charger.begin ()){
66
+ // If the charger fails to initialize, it will blink the red LED
67
+ while (true ){
68
+ blinkLed (LEDR);
69
+ }
70
+ }
71
+
59
72
if (!board.begin ()){
60
73
// If the board fails to initialize, it will blink the red LED
61
- pinMode (LEDR, OUTPUT);
62
74
while (true ){
63
- digitalWrite (LEDR, LOW);
64
- delay (1000 );
65
- digitalWrite (LEDR, HIGH);
66
- delay (1000 );
75
+ blinkLed (LEDR);
67
76
}
68
77
}
69
78
79
+ delay (10000 ); // -> Give time to take the measurement
70
80
charger.setEnabled (false ); // -> Please measure if it makes a difference
71
81
delay (10000 ); // -> Give time to take the measurement
72
82
0 commit comments