Skip to content

Commit 787e410

Browse files
committed
Cleaning up last example
1 parent 0b4ba7a commit 787e410

File tree

3 files changed

+12
-18
lines changed

3 files changed

+12
-18
lines changed

examples/Example3_ChangeAddress/Example3_ChangeAddress.ino

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -37,41 +37,35 @@ void setup()
3737

3838
Wire.begin();
3939

40+
// This sketch wont' run until you open the serial monitor
4041
while(!Serial)
4142
;
4243

4344
// Attempt to begin the sensor
44-
if (myUltrasonic.begin(deviceAddress) == false)
45+
if (myUltrasonic.begin(kQwiicUltrasonicDefaultAddress) == false )
4546
{
4647
Serial.println("Ultrasonic sensor not connected, check your wiring and I2C address!");
47-
while(1)
48-
;
4948
}
5049

5150
Serial.println("Ready to change address.");
5251
delay(1000);
5352

54-
}
55-
56-
void loop()
57-
{
5853
Serial.print("Changing Address To: ");
5954
Serial.println(NEW_ADDR, HEX);
55+
6056
// Call change address.....
6157
myUltrasonic.changeAddress(NEW_ADDR);
6258
delay(1000);
6359

64-
Serial.println("Attempting to communicate with new address...");
65-
if (myUltrasonic.begin(NEW_ADDR) == false)
66-
{
67-
Serial.println("Ultrasonic sensor address did not change, ensure you picked a viable address.");
68-
while(1)
69-
;
70-
}
71-
72-
Serial.println("Address changed successfully: ");
73-
Serial.println(NEW_ADDR, HEX);
7460

61+
Serial.print("Load up example 1 with the new address at: ");
62+
Serial.println(NEW_ADDR, HEX);
63+
Serial.println("Freezing....");
7564
while(1)
7665
;
66+
67+
}
68+
69+
void loop()
70+
{
7771
}

library.properties

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,3 @@ paragraph=
77
category=Sensors
88
url=https://github.com/sparkfun/SparkFun_Qwiic_Ultrasonic_Arduino_Library
99
architectures=*
10-
depends=SparkFun Toolkit

src/sfeQwiicUltrasonic.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ sfeTkError_t sfeQwiicUltrasonic::changeAddress(uint8_t &address)
8484
// Check whether the address is valid
8585
sfeTkError_t err;
8686
size_t numBytes = 2;
87+
// We want to shift the address left before we send it.
8788
address <<= 1;
8889
const uint8_t toWrite[2] = {kUltrasonicAddressChangeCommand, address};
8990

0 commit comments

Comments
 (0)