Prevent execution of the rest of example program if begin fails
The example sketch checks the return value of the nau.begin() call. If it returns false, the example sketch prints the helpful "Failed to find NAU7802" message to Serial. Previously it then proceeded with the program execution (including inappropriately printing "Found NAU7802"). The rest of the program can not work correctly if the initialization failed. It might even crash some boards, causing the useful "Failed to find NAU7802" message to not be seen by the user. The more user friendly behavior implemented here is for the example sketch to go into a perpetual loop if the initialization failed.
This commit is contained in:
parent
a41c9b1bde
commit
b3203ef2f6
1 changed files with 2 additions and 1 deletions
|
|
@ -7,6 +7,7 @@ void setup() {
|
|||
Serial.println("NAU7802");
|
||||
if (! nau.begin()) {
|
||||
Serial.println("Failed to find NAU7802");
|
||||
while (1) delay(10); // Don't proceed.
|
||||
}
|
||||
Serial.println("Found NAU7802");
|
||||
|
||||
|
|
@ -72,4 +73,4 @@ void loop() {
|
|||
}
|
||||
int32_t val = nau.read();
|
||||
Serial.print("Read "); Serial.println(val);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue