Skip to content

Commit 678a376

Browse files
committed
Improve readability
1 parent 830df36 commit 678a376

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

examples/Standby_WakeFromRTC_H7/Standby_WakeFromRTC_H7.ino

+20-10
Original file line numberDiff line numberDiff line change
@@ -39,34 +39,44 @@ Board board;
3939
Charger charger;
4040
MAX1726Driver fuelgauge(&Wire1);
4141

42+
void blinkLed(int ledPin, int delayTime = 1000){
43+
digitalWrite(ledPin, LOW);
44+
delay(delayTime);
45+
digitalWrite(ledPin, HIGH);
46+
delay(delayTime);
47+
}
48+
4249
void setup() {
4350
// When uploading this sketch to the M4 core, it just goes to standby mode.
4451
#if defined(ARDUINO_GENERIC_STM32H747_M4)
4552
board.standByUntilWakeupEvent();
4653
return;
4754
#endif
48-
49-
charger.begin();
5055

51-
// Turn off the built-in LED
56+
pinMode(LEDR, OUTPUT); // Used to indicate errors
57+
digitalWrite(LEDR, HIGH); // Turn off the red LED
5258
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
5461

5562
// Turn on the blue LED to show that the board is still awake
56-
pinMode(LEDB, OUTPUT);
5763
digitalWrite(LEDB, LOW);
5864

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+
5972
if(!board.begin()){
6073
// If the board fails to initialize, it will blink the red LED
61-
pinMode(LEDR, OUTPUT);
6274
while (true){
63-
digitalWrite(LEDR, LOW);
64-
delay(1000);
65-
digitalWrite(LEDR, HIGH);
66-
delay(1000);
75+
blinkLed(LEDR);
6776
}
6877
}
6978

79+
delay(10000); // -> Give time to take the measurement
7080
charger.setEnabled(false); // -> Please measure if it makes a difference
7181
delay(10000); // -> Give time to take the measurement
7282

0 commit comments

Comments
 (0)