File tree Expand file tree Collapse file tree 3 files changed +12
-18
lines changed
examples/Example3_ChangeAddress Expand file tree Collapse file tree 3 files changed +12
-18
lines changed Original file line number Diff line number Diff line change @@ -37,41 +37,35 @@ void setup()
37
37
38
38
Wire.begin ();
39
39
40
+ // This sketch wont' run until you open the serial monitor
40
41
while (!Serial)
41
42
;
42
43
43
44
// Attempt to begin the sensor
44
- if (myUltrasonic.begin (deviceAddress ) == false )
45
+ if (myUltrasonic.begin (kQwiicUltrasonicDefaultAddress ) == false )
45
46
{
46
47
Serial.println (" Ultrasonic sensor not connected, check your wiring and I2C address!" );
47
- while (1 )
48
- ;
49
48
}
50
49
51
50
Serial.println (" Ready to change address." );
52
51
delay (1000 );
53
52
54
- }
55
-
56
- void loop ()
57
- {
58
53
Serial.print (" Changing Address To: " );
59
54
Serial.println (NEW_ADDR, HEX);
55
+
60
56
// Call change address.....
61
57
myUltrasonic.changeAddress (NEW_ADDR);
62
58
delay (1000 );
63
59
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);
74
60
61
+ Serial.print (" Load up example 1 with the new address at: " );
62
+ Serial.println (NEW_ADDR, HEX);
63
+ Serial.println (" Freezing...." );
75
64
while (1 )
76
65
;
66
+
67
+ }
68
+
69
+ void loop ()
70
+ {
77
71
}
Original file line number Diff line number Diff line change @@ -7,4 +7,3 @@ paragraph=
7
7
category =Sensors
8
8
url =https://github.com/sparkfun/SparkFun_Qwiic_Ultrasonic_Arduino_Library
9
9
architectures =*
10
- depends =SparkFun Toolkit
Original file line number Diff line number Diff line change @@ -84,6 +84,7 @@ sfeTkError_t sfeQwiicUltrasonic::changeAddress(uint8_t &address)
84
84
// Check whether the address is valid
85
85
sfeTkError_t err;
86
86
size_t numBytes = 2 ;
87
+ // We want to shift the address left before we send it.
87
88
address <<= 1 ;
88
89
const uint8_t toWrite[2 ] = {kUltrasonicAddressChangeCommand , address};
89
90
You can’t perform that action at this time.
0 commit comments